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: Concrete mediators and the viewComponent  (Read 7134 times)
eco_bach
Courseware Beta
Sr. Member
***
Posts: 81


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



View Profile WWW Email
« Reply #1 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>

Logged
Pages: [1]
Print