PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: marcink on December 24, 2008, 02:49:35



Title: command modifies viewComponent??
Post by: marcink on December 24, 2008, 02:49:35
hi all,

is it allowed to modify a viewComponent directly from a command?

i have a MacroAsyncCommand with three AsyncCommands: FadeOut, Update and FadeIn.
each of the subcommands modifies the view directly.

i know i could make it like: call 1st command from mediator, when 1st command sends notification that its finished, mediator modifies the view, then calls the 2nd command... and so on.
but with this, i would add lots of constants to the app.

i would like to know, if the first approach is allowed or not.

thanks!!


Title: Re: command modifies viewComponent??
Post by: puremvc on December 25, 2008, 06:20:01
Sometimes there are situations that require the view component to be updated in the way that you describe. In these cases, you can retrieve the mediator, and access its view component. You have to make the typed getter public on the mediator.

The only problem with this and why it is cautioned against is that it spreads around knowledge of the view component, such that if that component is modified, multiple actors may need to be refactored. This is why the mediator is generally the only point of contact with that component.

Ways to reduce code smell when you do this are to cleanly implement your 'API' of props and methods for the component so as to encapsulate as much of its internal implementation (which you should be doing as a matter of course to protect the mediator, but now its even more important). Consider making the component implement an interface and only make calls against the interface (i.e. The typed getter returns an interface type rather than a class).

-=Cliff>


Title: Re: command modifies viewComponent??
Post by: marcink on December 25, 2008, 12:28:02
hi cliff,

thanks for the answer...
i'm quite new to patterns, so sometimes i'm not very confident hot to use it... :)

anyway, thanks!