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: Sharing the PureMVC Facade Instance between Flex libraries  (Read 13527 times)
punchjunkie
Newbie
*
Posts: 9


View Profile Email
« on: February 05, 2008, 02:27:24 »

Hello all,

First off, we just recently converted our first project into the pureMVC architecture with great success. It's helping immensely with maintenance around here and everyone loves this new approach.

My question is as follows; we currently are building a flex, framework library that we can utilize for all our core business functions. What is the best a approach utilize PureMVC architecture between libraries?

At this point, for commands that i've created in the framework library, I added a parameter from to pass the facade instance in. It seems to be working with this approach, but I wanted to know if there is a better way to do this.

Thanks!

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



View Profile WWW Email
« Reply #1 on: February 06, 2008, 09:52:00 »

Tony,

You shouldn't have to make any special facility for getting the Facade to a Command because it happens to be in a library. It should extend SimpleCommand and so, when instantiated by the controller in your app, the Facade it will have access to is the one that's already been instantiated inside your app.

You may create a Facade in your library, but just use it to define constants. It should not have any methods, or ever need to be instantiated.

Your ApplicationFacade will register Commands against notifications names defined on the Facade in the library.

Generally, Commands in the library should handle the creation and registration of Proxies and Mediators in that library, reducing the burdon on the developer using the library.

Shortly there will be several really good examples of utilities available. In preparation for releasing 2.0 of the framework, I'm migrating all the demos. As I go, I'm extracting utilities.

For instance the CodePeek AIR Demo will yield 2 utilities;
  • XMLDatabase for persisiting and working with XML databases,
  • WindowMetrics for allowing all AIR apps to be good desktop citizens by remembering  their desktop and monitor position as well as maximized state, and restoring it on startup.

And, because WindowMetrics makes use of XMLDatabase for persistence of info, we'll see examples of inter-utility dependence.

Also Phil Sexton and others here have really iterated the resource loading mechanism that's at the heart of Jens Krause's Application Skeleton demo, and so we'll have a StartupManager utility with corresponding demo that shows how the resources to be loaded can be dependent on each other's completion.

Certainly return to this thread with any further questions you may have about creating utilities using the framework.

Oh, one last thing, definitely DON'T include the framework classes in your utility. Let the implementing app do that. And make sure you note which version of the framework your utility is compatible with.

-=Cliff>
Logged
punchjunkie
Newbie
*
Posts: 9


View Profile Email
« Reply #2 on: February 06, 2008, 12:03:55 »

I appreciate the quick and detailed response!  :) 


I had started going in that direction towards that end of the day. What I did was actually create proxies and commands in the external library, register them in the main application facade and communicate with the proxies/commands through the application mediator & notifications. So, in essence, is it best to keep mediators out of external libraries?

If a mediator is created in the external library(utility), how would I a proxy from the application facade instantiated from the main app?

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



View Profile WWW Email
« Reply #3 on: February 06, 2008, 09:48:57 »

Mediators can go into libraries as well. You just have to orchestrate overall registration from the main app.
-=Cliff>
Logged
punchjunkie
Newbie
*
Posts: 9


View Profile Email
« Reply #4 on: February 11, 2008, 10:54:55 »

Hi Cliff,


I have been able to successfully use commands and proxies in external libraries, but I haven't been able to use a mediator in an external library.

I don't want to create a circular references with the parent application but I haven't found out how to access the application facade from an mediator in an external library.

For example, I have a mediator in an external library that i would like to retrieve a proxy from the application facade. Do you have an example or could you please explain how I would accomplish this?

Example:
:

import org.puremvc.interfaces.IMediator;
import org.puremvc.interfaces.INotification;
import org.puremvc.patterns.mediator.Mediator;
import org.puremvc.patterns.observer.Notification;

public class MyMediator extends Mediator implements IMediator
{


public static const NAME:String = 'MyMediator ';
                private var myProxy:MyProxy ;


public function MyMediator ( viewComponent:Object )
{
super( viewComponent );

// HOW WOULD I ACCOMPLISH THE STATEMENT DIRECTLY BELOW?
  myProxy= facade.retrieveProxy( MyProxy.NAME ) as MyProxy;
}




Thanks for your time!

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



View Profile WWW Email
« Reply #5 on: February 11, 2008, 11:33:58 »

Hi Tony,

The code you posted seems correct. What difficulties are you finding with it?

-=Cliff>
Logged
punchjunkie
Newbie
*
Posts: 9


View Profile Email
« Reply #6 on: February 11, 2008, 12:30:39 »

Thanks for the quick response!

Here is my problem:


I have a AIR application(the main app), let's call it 'app_A' and a flex library project called 'lib_B'.


I want to create a mediator in to be used in 'app_A' in the 'lib_B' library.


In order to get access to the facade singleton from 'app_A' in the 'lib_B' flex library i would have to add the circular reference to 'app_A' as follows:


import com.app_A.ApplicationFacade;


How do I go about getting access to the Facade singleton in the mediator in 'lib_B' without creating this circular refence. The only thing I could think of was passing an instance of the facade in the mediator constructor..

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



View Profile WWW Email
« Reply #7 on: February 12, 2008, 09:09:36 »

Refer to the IFacade interface inside the library. You shouldn't be calling or referring to anything on the concrete facade that isn't defined on the IFacade interface.

-=Cliff>
Logged
Pages: [1]
Print