python - Class inheritance, how to improve? -


i have little question discouraging me have portion of code:

class a(object):     def __init__(self):         self.variable = "hello world!!!"  class b(a):     def __init__(self):         self.a = a()         self.inherited = self.a.variable 

the thing have bunch of variables on class don't want instantiate , declare on class b 1 one there way improve code?

you using mix of composition , inheritance. seems want exclusively use composition:

class a(object):     def __init__(self):          self.c = c()          self.e = e()  class b(object):     def __init__(self):         self.c = c()         self.d = d() 

where c, d, , e components group variables , methods together. , b share component of c. should more complete composition tutorials

edit: double checking looks confused instantiating super class variables. other answers correctly addressed super


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -