News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Understanding the Observer Pattern
February 23, 2012 @ 11:39:10

PHPMaster.com has a new tutorial looking at another popular design pattern, the Observer pattern, and sharing some example code putting it to use. (Their other design pattern articles include ones on command and factory patterns).

In this article I'll show you how to implement the Observer Pattern. You'll learn how various classes in the pattern relate to one another as subject and observers, how the subject notifies observers of a change in its state, and how to identify scenarios where it would be suitable to use the Observer Pattern in your own code.

The introduce the pattern by using an abstract "Observer" and "Subject" (that defines "attach", "detach", "getState", "setState", "notify" and "getObservers" methods) observer classes to coordinate the attached classes. They extend these classes with "Auth" and "Auth_ForumHook" show how to attach the "Auth_ForumHook" classes to the main "Auth" observer manager and change the state of the observer to notify it of an update.

You can find a more detailed explanation of the Observer pattern on Wikipedia.

0 comments voice your opinion now!
observer design pattern tutorial authorization


blog comments powered by Disqus

Similar Posts

WebReference.com: The Building Blocks: Data Types, Literals, Variables, and Constants - Part 2

ZendCasts.com: Building a JSON Endpoint with SLIM (Part 1)

DevShed: Introducing Mediator Classes in PHP 5

Michael Nitschinger: Caching Doctrine Entities with Couchbase

NETTUTS.com: Kohana: The Swift PHP Framework


Community Events





Don't see your event here?
Let us know!


framework tips api series symfony introduction deployment community install podcast language list opinion package release interview zendserver library update laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework