I have the following problem and I need advice on how to solve it the best technically in Python. As I am new to programming I would like to have some advice.
So I will have the following object and they should store something. Here is an example:
object 1: cash dividends (they will have the following properties)
- exdate (will store a list of dates)
- recorddate (will store a list of dates)
- paydate (will store a list of dates)
- ISIN (will store a list of text)
object 2: stocksplits (they will have the following prpoerties)
- stockplitratio (will be some ration)
- exdate(list of dates)
- ...
I have tried to solve it like this:
class cashDividends(object):
def __init__(self, _gross,_net,_ISIN, _paydate, _exdate, _recorddate, _frequency, _type, _announceddate, _currency):
self.gross = _gross
self.net = _net
self.ISIN = _ISIN
self.paydate = _paydate
self.exdate = _exdate
self.recorddate = _recorddate
self.frequency = _frequency
self.type = _type
self.announceddate = _announceddate
self.currency = _currency
So if I have this I would have to create another class named stockplits and then define an __init__ function again.
However is there a way where I can have one class like "Corporate Actions" and then have stock splits and cashdividends in there ?
__init__that only sets up required parameters. Then define additional methods to preform or store other tasks. Look at the first figure here. Eventually you may want to make a master class that defines common methods, and subclasses that do specific work. That concept is called inheritance which is described at that link as well.