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: Using the ApplicationFacade when sending notifications of events?  (Read 10247 times)
saraterp
Newbie
*
Posts: 1


View Profile Email
« on: March 23, 2009, 08:07:33 »

Is it best practice to ALWAYS use the ApplicationFacade when sending notification(s) of events from mediators?

It appears easy enough to just use sendNotification(note) without using the ApplicationFacade; however, I do not know what may result (negatively or positively) in doing so.

Any help is greatly appreciated!

Thanks,
Sara
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: March 23, 2009, 03:27:38 »

SendNotification is a convenience method present in all INotifiers (Commands, Mediators and Proxies) which simply passes through to the Facade method of the same name. So facad.sendNotification and sendNotification are functionally equivalent. Its possible you might save a processor cycle or two by using facade.sendNotification, but at the expense of extra characters in the code for all the 'facade.' personally I use the local convenience method. 
-=Cliff>
Logged
landed
Full Member
***
Posts: 37


View Profile Email
« Reply #2 on: April 29, 2009, 04:40:25 »

I post this question within this thread as it seems appropriate

I have in my concrete facade the following 2 lines separated however

:
registerCommand( STARTUP, StartupCommand );
       
sendNotification( STARTUP,stage);


So indeed when we sendNotification in this case the class StartupCommand class has its 'execute' method involked ? (execute being a necessary method for the Interface)

So if I want to communicate from no matter where to no matter what I can use this way. The above comes from an Ifacade. I just would like to know how to communicate for example from mediator a to mediator b... (mediator is like a view and should only really be concerned with displaying its self correctly so bad example ?) what about communication between a model proxy e.g. (as some business logic has been done) to mediator a - where we want to see this data visually.

thanks for following
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: April 30, 2009, 04:40:43 »

sendNotification also works to send information from one mediator to another, a frequent line of communication to keep disparate views in sync. Mediators are interrogated as to their notification interests at registration by having their listNotificationInterests method called. Afterwards, they receive notes in the handleNotification method.

-=Cliff>
Logged
landed
Full Member
***
Posts: 37


View Profile Email
« Reply #4 on: May 01, 2009, 05:56:28 »

Ok I have got a mini application (my first using pmvc) running- but it isnt really leveraging the framework yet other than it starts up at a basic level.

Its a simple addition calculator that adds two text field together when you click "do sum"

And it looks like this so far

facade(kind of like old skool frame1, some stuff happening here)
model: (yet to make)
view:StageMediator
controller:StartUpCommand and DoSum

That's all so far. I have my view elements created in StageMediator at the moment and not really separated into views though I'm using composite classes for text fields and simple buttons.

Flow of the application

I have Main.as as a document level class which is getting the facade going by passing in a refference to the stage...
The facade upon startup launches StartUpCommand

StartUpCommand :Then registers and creates the StageMediator and builds the view elements into itself.

StageMediator:Actions - handlers exist in this Mediator (viewish thing) and I could even do the application logic here- was before I moved it into DoSum (a command) .

My question is with regular MVC I should perform the calculation in the model, so I guess I create one (or do i create a proxy instead) and do the calculation there. And then update the result in the view.

Bigger question - what is the correct way in pseudo code to do the communication.

In the view I have the two values in the text fields that I place into and object and I send that object to my doSum command with sendNotification(LandedFacade.DO_SUM,obj);

In the execute method of DoSum I get the values as obj... or does the frame work allow me to pass this object straight to the model (I thought the facade allows me to do this). This is what im still unclear about. But currently im trying to send it to the DoSum controller then that sends it to the model for actually doing the sum ??? Its this extra chain of responsibility that is the decoupling of MVC.

I would love to get help on understanding this last paragraph in the context of this very simple application. Thanks

 
Logged
landed
Full Member
***
Posts: 37


View Profile Email
« Reply #5 on: May 01, 2009, 07:19:18 »

First abuse - Well I tried as it was such a simple application to just create my user intervace and view elements inside the mediator class. Instead I should have a specific view class and do something like this

:
                    var form:Form = new Form( stage );
                    facade.registerMediator(new FormMediator( form ));

in the above we create a distinc view callled Form, the facade is used then to create its mediator.

I cannot now call a sendNotification from the view !and still original question applies.

It seems all the examples use old skool dispatch event to tell the mediator that something happened. Ok so I do that for now. Also a small gotcha in the Mediator you have to have the following or the name of the view wont resolve as you might think...

:
private function get form():Form
        {
            return viewComponent as Form;
        }
« Last Edit: May 01, 2009, 08:47:27 by landed » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: May 01, 2009, 11:08:31 »

Is there a 'new skool' replacement for events I haven't heard about? :)

Events are the basic way for flash components to communicate in a decoupled way. By dispatching an event and listening for it in the mediator you're left with a more portable component that doesn't need to know about the framework.

-=Cliff>
Logged
landed
Full Member
***
Posts: 37


View Profile Email
« Reply #7 on: May 01, 2009, 12:13:53 »

No just that its nice to send some object along with an event I thought that the framework had a system for doing this and I wanted to make sure I am doing things properly.
I see that for a few of the examples a lot of the business logic is handled in the mediators and that the model is doing more higher level business logic. I dont mind this in fact as it represents a real world better. I just have to think of this framework as something new not as MVC and it will become easier I guess.
thanks
Logged
Pages: [1]
Print