Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: instantiating views inside of their mediators  (Read 3508 times)
masterkrang
Newbie
*
Posts: 7


View Profile Email
« 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.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 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>
Logged
masterkrang
Newbie
*
Posts: 7


View Profile Email
« Reply #2 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...
Logged
Pages: [1]
Print