Python: Is passing a main class to other classes a bad idea? -
i've got main class holds program's mainloop , other variables , such.
class main: def __init__(self): blah = 'blah' blah2 = 'blah' blahhandler = blahhandler.blahhandler(self) blahhandler2 = blahhandler.blahhandler2(self) def mainloop(self): < irrelevant junk > but passing 'self' blahhandlers bad idea, handlers can stuff such as..
#in class 'blahhandler' self.main.blahhandler2.doblah() print(self.main.blah) or should pass blahhandler2 directly blahhandler rather passing whole main class? sorry if incomprehensible because sounds 'blah'.
thanks!
there nothing wrong passing main object blahhandler doing.
which 1 better depends entirely 1 objects represent. here few questions started:
- does make sense
blahhandlerhave own referenceblahhandler2, or whenblahhandlerrefererringblahhandler2referringblahhandler2it'smainowns? - should
blahhandlerhave referencemain, or attributesmainshould hiddenblahhandler?
ask questions these structure on in development, because have works , isn't bad practice, doesn't mean makes sense (but might!).
don't worry passing "the whole main class" speed or memory perspective, passing reference.
Comments
Post a Comment