PureMVC Architects Lounge

PureMVC Manifold => Standard Version => Topic started by: masterkrang on February 06, 2011, 07:46:45



Title: instantiating views inside of their mediators
Post by: masterkrang on February 06, 2011, 07:46:45
Is it a good idea to instantiate you views within their mediators? I just received a project where the views were instantiated inside their mediators. Is there any benefit to me. I feel like this further couples the view to the mediator, and doesn't make a whole lot of sense. The way I'm used to doing it is to instantiate views in my main application, then on startup link your views to their mediators. Any advice? Thanks.


Title: Re: instantiating views inside of their mediators
Post by: puremvc on February 08, 2011, 05:45:33
As long as the View Component doesn't import the Mediator's class, then the coupling is only one way: Mediator->View Component. That is the desired direction of coupling. It doesn't really matter if the mediator creates the View Component or gets it passed to it. It can help if you need deferred instantiation of a class at runtime.

-=Cliff>


Title: Re: instantiating views inside of their mediators
Post by: masterkrang on February 10, 2011, 11:25:27
Good to know, thanks Cliff. I decided to yank out a lot of the View functionality out of the Mediator. I started to think about what happens when I pull the View out of the application and drop it somewhere else, and in that light it seemed like the Mediator was doing too many thing for the View. In my mind, the Mediator is just there to facilitate interoperability between other part of the application, not to be like a mom that's always wiping the kid's nose. I also feel like instantiating the views inside the Mediators, then adding that view via viewComponent.addChild(view) isn't as readable as adding that view straight to the viewComponent itself. Just a thought...