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

Show Posts

* | |

  Show Posts
Pages: [1]
1  Announcements and General Discussion / Architecture / Re: Multiple applications with the same core [flash] on: May 13, 2009, 11:40:10
Hi,

This is the solution I settled on and I think it would work for you as well. It might not be the simplest but so far it works for me :-)

The key is using interfaces instead of classes in some places. This makes it possible to change the actual class without having to change the import statement (which would create a cascading effect).

So how I have gotten it to work:

Instead of directly creating components, mediators and proxies in classes, I create them through a ComponentFactory. This component factory is different for each version of the application and returns an instance of a mediator or something else.

Some code to clarify:

In the document class I have this:

:
import interfaces.IComponentFactory;
import ComponentFactory; // the component factory for this specific application

public function startApplication():void
{
facade = ApplicationFacade.getInstance();
facade.startup( this.stage, new ComponentFactory() ); // the component factory is send along
}

In the facade I store a reference to the factory so every other class can reference it

:
public function startup( stage:Object, factoryReference:IComponentFactory):void
{
factory = factoryReference;
}

Now if an mediator would like to create new mediators it would do something like the following. For you it would create a proxy.

:
import IComponentFactory;
import IMediatorPlus;

private function initializeSite():void
{
private var factory:IComponentFactory = ApplicationFacade.getInstance().factory;
site = factory.createSite() as MovieClip;
var siteMediator:IMediatorPlus = factory.createSiteMediator(site);
facade.registerMediator(siteMediator);
stage.addChild(site);
siteMediator.init();
}

So what happens in the component factory? Well, nothing much but since it's contents are 'hidden' by using a proxy it is easy to use a different component factory that creates different components without have to change any mediators or such that reference it.

:
public class ComponentFactory implements IComponentFactory
{

public function createSite():IBasicComponent
{
return new Site();
}

public function createSiteMediator( component:Object ):IMediatorPlus
{
return new SiteMediator(component);
}

}

As I said it might not be the simplest or best solution so if anybody has ideas on how it could be improved please post them.

Bob
2  Announcements and General Discussion / Architecture / Re: Multiple applications with the same core [flash] on: April 23, 2009, 11:49:29
Thanks.

I have gotten something a bit similar working but your solution is more elegant. I'll give it a try. Thanks again.

regards,

Bob
3  Announcements and General Discussion / Architecture / Re: Multiple applications with the same core [flash] on: April 23, 2009, 09:49:14
Thanks for your reply.

Using a different document class for each is what I had in mind. But I can't figure out a reliable way to use that as a basis to create different components and mediators without having to change the surrounding classes as well.

Right now I have the following:

SiteEntry (Document Class)
ApplicationFacade
- StartupCommand creates a StageMediator
StageMediator creates the SiteMediator which in turn creates the other view components and mediators.

SiteMediator is the one that needs to be adapted for each application but I would like handle the changes from SiteEntry. Without having a different ApplicationFacade, StartupCommand, etc.

Bob
4  Announcements and General Discussion / Architecture / Multiple applications with the same core [flash] on: April 23, 2009, 08:14:17
Hi,

This is probably a very simple question but is has me stumped for a while now.

I'm building several sites with Flash CS4 with the same core taking care of loading, navigation, interface logic, etc. Mostly the visual elements (components) will be different with perhaps a few changes to the mediators.

Of course I want the custom code for each project to be as little as possible but I have trouble figuring out how to approach this. If I uses custom classes somewhere in the application they have to be imported making the importing class custom as well, etc.

What I would like to do is have the base class that is defined in the FLA be different for each application. This class would define it's own AbstractFactory which later on in the application creates the required components and mediators.

This way I can keep the ApplicationFacade, startup logic, proxies, etc identical for each application.

So that's the theory. But I can't figure out how to make it work :-(

Any help would be much appreciated.

Bob

Pages: [1]