News Feed
Sections




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

PHP-Tip-a-Day:
PHP Tutorial King Floyd and the Seventeen Princes - A Tale of the Observer Pattern
June 22, 2012 @ 09:20:39

On the PHP-Tip-a-Day site today there's an new "fable" posted in the Design Pattern Fables series. This time it's about the Observer pattern (and kings and princes).

The first place I recall encountering the observer pattern was not in PHP, but in JavaScript. If you've ever set a listener to fire when an event happened, you've used the observer pattern. Functions or methods are registered with an object so that when it experiences a specific event, it "notifies" the registered functions or methods by calling them.

His story tells about a royal family, a pregnancy and magic mirrors that allows for instant communication between the family and outlying locations. He relates it to the objects and "watchers" that make up the Observer pattern and gives a brief code example (in Javascript) of a HTML button and a jQuery event observer that fires when it's clicked.

0 comments voice your opinion now!
designpattern fable story observer event watcher


blog comments powered by Disqus

Similar Posts

MaltBlue.com: Are TableGateways Worth it in Zend Framework 2?

Dagfinn Reiersol's Blog: Real programming with PHP 5.3 (part 4): A more realistic example

Community News: PRADO Watch Blog Launched

Pádraic Brady's Blog: Complex Web Pages with the Zend Framework?

Community News: Atlanta PHP & Atlanta MongoDB Host Derick Rethans


Community Events





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


unittest introduction bugfix wordpress language api laravel podcast library list developer community application configure release code install interview series threedevsandamaybe

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