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: Data Request from Components  (Read 6244 times)
saad
Sr. Member
****
Posts: 65


View Profile Email
« on: June 13, 2012, 12:40:29 »

I'm not sure, I read an example somewhere for a best strategy to implement.

For instance,

1) a component needs some data at user request (click of a button), event is dispatched.
2) Mediator in the listener function retrieves the proxy and calls the function on it.
3) Proxy makes the data request and has a handler method for the response.
4) Proxy then sends the notification once data is ready inside handler method
5) Notification is received by the same Mediator in this case, and populates the component.

For me it seems like a long trip, is there a shorter way?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: June 13, 2012, 12:45:59 »

For me it seems like a long trip, is there a shorter way?
Not if you want to loosely-couple your app's actors which is generally considered the right thing to do in an OOP application.

There are only 3 actors involved - the component, the mediator, and the proxy. If you let the component know about the proxy then your component is no longer portable, as it is tied to the framework and to the your application model.

Consider an office situation where the actors are The Boss (component), Her Secretary (mediator), and The Client (proxy).

Now the Boss wants some info from the Client, but she's a busy gal who doesn't have time to look up the phone number of the contact in the CRM database (which she may not even know or care how to operate), and call (and possibly have to keep calling back until he catches the contact in the office) so she gets her secretary on the intercom, who she tells to get info X from client Y, and goes back about her business. The Secretary 'takes care of it' and rings the Boss back on the intercom with the info when she gets it. QED.

That seems like an ordinary sort of setup, right? Sure the boss could get the info but that's what the Secretary is there for, to insulate the Boss from all the fiddly details of communication so that she can focus on her responsibilities.

It's not always about shortest path in OOP. It's about loose-coupling and finding the appropriate roles, responsibilities, and collaborations of your actors.
« Last Edit: June 13, 2012, 12:59:50 by puremvc » Logged
Pages: [1]
Print