When to a refactor?

So, I wrote my first Python application of more than trivial size, and I did it procedurally because it was the information that I have learned best so far. Now I want to reorganize it to try (and finally) understand classes and OOP. My question is about best practices for developing classes, as each one develops from a simple start.

So, let's say I have an application that simulates an investment portfolio of short-term stock options. This means that at any given time I can have a portfolio (container) consisting of packages of short-term options, as well as long shares (of short options that were later exercised / assigned).

So, in terms of nouns, a lot is going on. There are data / attributes / methods applicable to any any kind of equity, data / attributes / methods specific for placing options (vs options), as well as data / attributes / methods specific for short put options (long put options), I could conceptually have:

class Option(object):
    """Describes an Option"""
    pass

class Put(option):
    """Describes an Option that is a Put"""
    pass

class Call(option):
    """Describes an Option that is a Call"""
    pass

class ShortPut(Put):
    """Describes a Put that is written (sold short)"""
    pass

class LongPut(Put):
    """Describes a Put that is purchased"""
    pass

class ShortCall(Call):
    """Describes a Put that is written (sold short)"""
    pass

class LongCall(Call):
    """Describes a Put that is purchased"""
    pass

# then more classes to describe stocks, holdings of a 
# given quantity of a stock or option at a specific price 
# on a specific date, and a portfolio to contain all the 
# holdings etc etc 

I am well on my way to a complete taxonomy. Maybe too much inheritance that I read may be bad. But it describes an object and allows us to distinguish between behavior / data as additional / different attributes are added. However, it seems that I have a huge number of forests that do nothing, because I can describe everything I need at this point with just a ShortPut object.

, , , . , :

class ShortPut(object):
    """Describes a short put"""
    pass

, , "". , , , . , put, put DRY. (base?) , :

class Put(object):
    """Describes an Option that is a Put"""
    pass

class ShortPut(Put):
    """Describes a Put that is written (sold short)"""
    pass

class LongPut(Put):
    """Describes a Put that is purchased"""
    pass

, . , , , - "" - , ShortPut , , , -, , .

? , , , , "", . , , - . , , , , , , . !

+3
3

?

. , , , . " , " - , , (Python). , - "", " , ".

+1

, . , , , .

, , , , , , , OO (, , P/L ). .

Long/Short a Put/Call - , , . , , . , EuropeanCall/Put AmericanCall/Put.

, , "". , , , . , put, put DRY. (base?) , :

Mixin

+1

- , , , , , - , , , . , , ( TODO FIXME, . , .)

I know that stubbing with cases is common practice pass, but if you can avoid this and focus on one thing at a time, you might feel more productive. I, I’m always afraid that I’ll go stupid passbecause I forgot.

+1
source

All Articles