News Feed
Sections




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

Zend Developer Zone:
Observer pattern in PHP
February 24, 2009 @ 12:08:32

On the Zend Developer Zone there's a new tutorial posted about the Observer pattern (one of many design patterns) and how it can help you create code using an event-driven programming style.

What exactly is an observer pattern ? All the theory is accessible on Wikipedia. Basically we have an object you want to monitor ( observe ) for any changes. Most of the time this object just fires out events and we want to listen to them. We can have more objects observing one or more other objects so basically this can be M:N relationship

He compares them to triggers in the database world - bits of code that are activated when something changes on an object. His example implements an interface (IObservable) to set/get an email address and validate it with a regular expression. When the setEmailAddress method is used and the validate method is called, the observer kicks into action and checks to ensure the value is correct.

0 comments voice your opinion now!
observer pattern designpattern interface implement email validate


blog comments powered by Disqus

Similar Posts

Juozas Kaziukenas' Blog: SQL Native Client as MSSQL driver for Zend Framework

Maarten Balliauw: Working with Windows Azure SQL Database in PhpStorm

Devshed: The Basics of Using the Prototype Pattern with PHP 5

DevShed: Centralizing the Validation of Data with the Observer Pattern in PHP

Reese Wilson: Using the ServiceManager as an Inversion of Control Container (Part 1)


Community Events





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


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

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