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 blahhandler have own reference blahhandler2, or when blahhandler refererring blahhandler2 referring blahhandler2 it's main owns?
  • should blahhandler have reference main, or attributes main should hidden blahhandler?

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

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -