So I am making a mario clone in pygame and I have a base class Character and two sub classes, Mario and Luigi. The methods that the Character class defines require a significant amount of attributes from a sub class (around 20) to be defined. For example, the initial y velocity of the Character instance must be defined. Should I be passing all these attributes to the Character class as parameters or should I just have them defined in the sub class (ie. Mario or Luigi)? Or what about a mix? My thinking is that since these properties are all required for a Character instance to have, that they should all be passed as parameters in the constructor of the class.
Here's some pseudo-code to demonstrate what I mean:
class Mario(Character):
def __init__(self):
Character.__init__(self, 1, 2, 3, 4, 5, ... 20)
class Character:
def __init__(self, var1, var2, var3, var4, var5, ... var20):
pass
OR
class Mario(Character):
def __init__(self):
var1 = 1
var2 = 2
var3 = 3
var4 = 4
...
var20 = 20
Character.__init__(self)
class Character:
def __init__(self):
pass
super
) is the right thing to do, as it means you can easily change how they're handled later.__init__
that applies to both sub-classes - if you do it in the base class, you only need to implement it once. Indeed, even with just the assignments from parameters to attributes, you're typing the same thing twice for no reason.