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: What is the purpose of the Observer?  (Read 7459 times)
skasssam
Jr. Member
**
Posts: 18


View Profile Email
« on: June 13, 2008, 08:19:34 »

Now that I am waist deep in my app I have a better understanding of PureMVC (mediators, proxies, notifications, etc...)

But where do observers fit into the big picture?

Anyone can provide insight?

TIA,
Shinan
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: June 13, 2008, 02:17:54 »

The Observer class is internal to the framework's notification system.

The View class maintains a map of observer lists; an associative array where the key is the notification name and the value is an array.

The observer list contains Observer instances, one for each mediator or command to be sent notifications by that name.

The observer has a reference to an instance of some class to notify (the 'notify context') and the method to call.

In the case of a mediator, when it is registered, it is queried as to its notification interests. For each notification name returned, an observer is created with that mediator as the context and 'handleNotification' as the 'notify method'. The observer is added to the list for the notification name in question.

In the case of commands, it is a little different. The command isn't actually instantiated until it is needed; when the notification it is registered for is sent, the command must be created and have the notification passed to its execute method.

This instantiation and execution of the command is the job of the controller. So when a command is registered, the observer points not to the command instance (which doesn't exist yet) but instead to the controller. The notify method is executeCommand. So the observer instance for all commands actually points to the same instance and method, which determines from the notification name which command class to instantiate and execute.

-=Cliff>   
Logged
skasssam
Jr. Member
**
Posts: 18


View Profile Email
« Reply #2 on: June 19, 2008, 12:44:24 »

Thanks for the explaination. BTW, PureMVC has helped me alot building my Flex App. Thank You!
Logged
Pages: [1]
Print