Proposal for "Dispatcher"

» Metadata » Status
» Description

A notification center acts as a notification dispatch table.
It is used to notify other objects of interesting things, if
they meet certain criteria. This information is encapsulated
in Notification objects.

Client objects register themselves with the notification center
as observers of specific notifications posted by other objects.
When an event occurs, an object posts an appropriate notification
to the notification center. The notification center dispatches a
message to each registered observer, passing the notification as
the sole argument.

The NotificationCenter is actually a combination of three design
patterns: the Singleton, Mediator and Observer patterns. The idea
of the notification center is borrowed from
Apple's Cocoa framework.

The idea behind this package is to provide PEAR packages with a
simple and common way to notify observers. At the moment, each
package uses its own way.

Example cases:

  • Let's say you have a User object and a Shopping Cart object. The user fills her cart. The cart is stored in the database using a session id as the user is not logged in yet. When the user logs in, you want to change the session id using session_regenerate_id() in order to make your site more secure. The notification center allow the cart object to register as an observer for a 'UserDidLogin' notification coming from the User object and update the database accordingly.
    • In other cases, an object might be interested to know when an item is added to a cart by the user, for example to update remote stock information.
    • Use a log observer that will log every notifications as they happen and help debug your code.
    • Couple the notification center with a desktop notifier: see the not ready for production Net_Growl.
    • This package will for example also be useful for HTML_QuickForm 4 (when it is ready...) to post notifications when a form is submitted, this way allowing another object to block other form submissions from the same user (who might have double clicked the submit button) or perform other operations.

The notification center makes this kind of processes easy.
The common, difficult way is to pass objects along, which usually
over-complexify your code maintainance and reduce the reusability
of your objects.

PS: I don't have a Category for this package, please help

TODO:

  • Change the property names of Notification in order to make it easy to extend.
  • Implement having multiple notification centers.
  • Find a name for the package

Name proposals:

  • Event_Dispatcher + Event_Notification
» Dependencies » Links
» Timeline » Changelog
  • First Draft: 2005-01-01
  • Proposal: 2005-01-01
  • Call for Votes: 2005-01-14
  • Bertrand Mansion
    [2005-01-04 12:27 UTC]

    Added TODO and Name proposals

  • Bertrand Mansion
    [2005-01-13 15:16 UTC]

    Added unit tests.
    Added link to tgz package.

  • Thies C. Arntzen
    [2023-10-17 17:05 UTC]

  • Thies C. Arntzen
    [2023-10-31 07:46 UTC]