PureMVC Architects Lounge

PureMVC Manifold => Standard Version => Topic started by: eco_bach on July 29, 2009, 11:21:28



Title: Concrete mediators and the viewComponent
Post by: eco_bach on July 29, 2009, 11:21:28
I've always assumed that the viewComponent in concrete mediators always references the Main class(passed in via  a notification body in the StartupCommand).

But on page 34 of the best practices document, I see the LoginPanelMediator constructor has the Loginpanel view as the viewComponent.

http://puremvc.org/component/option,com_wrapper/Itemid,30/

Can someone shed some light on this?

This might explain why  I'm having a heck of a time getting the implicit getters setters working properly...


Title: Re: Concrete mediators and the viewComponent
Post by: puremvc on July 31, 2009, 05:20:44
Keep in mind there are many mediators for many view components in a typical application.

The way you ensure that a given mediator gets a view component of the type it expects is to enforce that type at the constructor.

The Mediator.viewComponent property is type Object, and the Mediator constructor takes an Object and sets the viewComponent property with it. Everything displayable can be downcast to Object. 

However in your Mediator subclass, you write a typed getter so that you can retrieve the viewComponent property cast to the correct type and give it a meaningful name.

So when you access LoginPanelMediator.loginPanel through the implicit getter (from within the class or without), your LoginPanelMediator will try to cast the viewComponent Object to type LoginPanel.

This will fail if the viewComponent property isn't actually a LoginPanel object. Thus the need to ensure the type at the constructor.

-=Cliff>