failing to instantiate an inner class because of its order

Gabriel Genellina gagsl-py at yahoo.com.ar
Wed Dec 27 19:53:51 EST 2006


At Wednesday 27/12/2006 20:37, Pyenos wrote:

>class Model:
>     def fuck(self):print "fuck!"
>
>class View:
>         Model() #this part is fine
>
>class Controller:
>         def __init__(self):
>                 self.Model=Model()
>
>Controller().Model.fuck() #actually slight problem in previous solution
>
>
>Has to call in this way. I have confirmed this works.

The Model() inside View is *not* fine - you construct a Model 
instance just to discard it! Besides some side effects that 
constructing a Model() might have, this is useless.
If you are trying to implement a real MVC, usually the model exists 
by itself even before you need the view, so usually the view 
constructor gets the model as an argument.
I prefer to use lowercase attribute names: self.model = Model(), this 
way there is no confusion between model (an instance) and Model (a class).


-- 
Gabriel Genellina
Softlab SRL 


	

	
		
__________________________________________________ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 




More information about the Python-list mailing list