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: Should loaded view components be strongly typed by their mediator?  (Read 10443 times)
inchworm
Jr. Member
**
Posts: 13


View Profile Email
« on: March 24, 2010, 10:58:02 »

I have a view Mediator named MyMediator. It has a view component of type MyComponent so its getter looks like this:

:
import com.myproject.view.components.MyComponent;

protected function get myComponent():MyComponent
{
return MyComponent(viewComponent);
}

I also have an external swf whose document class is set to MyComponent. When I load up all of my application swfs I pass that loaded component to MyMediator:

:
facade.registerMediator( new MyMediator( myLoadedComponentReference ));
This is typically how I setup my mediators/components. However I realize now that because MyMediator imports MyComponent that I am compiling the MyComponent class in two places ( in the main application which holds my puremvc mediator and in the MyComponent swf ). This all seems very wrong to me as I believe things should only be compiled in one location, otherwise it's just wasting memory and potentially dangerous.

Do you guys have some opinions on all of this? Should loaded classes only be referenced by interface?

- rob
Logged
jpwrunyan
Sr. Member
****
Posts: 84


View Profile WWW Email
« Reply #1 on: March 25, 2010, 05:58:07 »

Do you guys have some opinions on all of this? Should loaded classes only be referenced by interface?

The way you worded your original post makes it sound like you've already decided what the answer is.  Which is yes, in this situation an interface would be apt.  You've convinced me, anyway.  Can you give any reasons why you wouldn't want to use an interface?
Logged
inchworm
Jr. Member
**
Posts: 13


View Profile Email
« Reply #2 on: March 26, 2010, 12:32:15 »

Not really, no  ;D

In this scenario an interface seems like the right thing to do. However I would like to cast the net a bit further and ask if it's wise to be creating my view components this way? Would it be better to keep all flash files separate and build my components with them through composition? So instead of using the view component class as the document class for my fla i would just load the fla's swf and my view component class would create/store an instance of it. Seems like that would lead to extra work when handling events out of the swf as the component would need to listen for events and then relay them to the mediator.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: March 26, 2010, 01:39:05 »

Interfaces are the way to go here.

-=Cliff>
Logged
inchworm
Jr. Member
**
Posts: 13


View Profile Email
« Reply #4 on: March 27, 2010, 11:37:29 »

Thanks for verifying my hunch guys.

Cliff — So it's ok for my view components to be document classes for flash files? I find this makes things very easy in many situations but I want to make sure the practice isn't frowned upon.

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: March 28, 2010, 12:45:07 »

So it's ok for my view components to be document classes for flash files?
Certainly.

-=Cliff>
Logged
Pages: [1]
Print