In an MVC framework, can a mediator be initialized in the view itself. So that as soon as view is instantiated...
Why a mediator has either to depend upon manual creation or only
after view's addchild is triggered ( automatic) ?
In an MVC framework, can a mediator initialized in the view itself.
So that as soon as view is instantiated, the constructor creates
the mediator of the view immediately. And then, with "getMediator"
method, the mediator instance of that view can be accessed ?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
vishwas.gagrani closed this discussion on 03 Aug, 2012 06:59 AM.
vishwas.gagrani re-opened this discussion on 03 Aug, 2012 06:59 AM
1 Posted by Abel de Beer on 03 Aug, 2012 01:49 PM
Hi Vishwas,
With Robotlegs, when you ask "can...?" then in general the answer is "yes": its flexibility allows you to do almost anything with little to no modification. However, following best practices is another thing. :)
The main role of the Mediator in Robotlegs is to separate application communication from the view implementation. It passes messages (events, signals) from the view component to the rest of the app and vice versa. This allows the view to become independent from the app, increasing reusability! So, to answer your question: a "getMediator" method doesn't make sense, because a view shouldn't know about what manages it. Here's a nice article by Stray about small and focused Mediators: http://www.xxcoder.net/my-mailman-doesnt-open-my-mail (and an interesting discussion in the comments as well!)
Regarding view instantiation and adding it to the stage: a pattern that I started to like is creating a Mediator for the context view. This Mediator can listen to the correct application events and create and add the views to the stage (and later remove them) when necessary. This, to me, feels more logical than doing that work from a Command, since Commands belong to the Controller tier. 2 notes about a "ContextViewMediator":
You can use
mediatorMap.mapView(contextView, ContextViewMediator);
to map the view to its Mediator.Always map the context view last, because its
onRegister
method will be called immediately.I hope this has given you a push in the right direction. Definitely come back if you have more questions!
Abel
2 Posted by vishwas.gagrani on 15 Aug, 2012 03:31 PM
Thanks, that was helpful .
vishwas.gagrani closed this discussion on 15 Aug, 2012 03:31 PM.