News Feed
Jobs Feed
Sections




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

Label Media Blog:
Design Patterns in PHP - Strategy Pattern
November 30, 2010 @ 12:48:26

On the Label Media blog today Tom Rawcliffe continues his series looking at design patterns (see here for his look at the Factory pattern) with this new post focusing in on the Strategy pattern.

The Strategy Pattern is used to decouple an algorithm from the context in which it is used. I'm going to equate this example to a real world scenario starring a man, I'll call him Bob.

In his example Bob heads to work and takes whatever way he wants to get there. His boss only cares that he makes it there, not the path he takes. Bob can take many different ways ("strategies") to get there, but how is up to him. Tom illustrates this with a bit of sample code with a "bob.php" that can use any number of other classes/methods to get to work (like commute, the train or a car).

0 comments voice your opinion now!
designpattern strategy pattern tutorial


blog comments powered by Disqus

Similar Posts

Zend: Extension Writing Tutorials - Resources (Part 3)

MaltBlue.com: Why Zend Framework Plugins Save You Time

VG Tech: Swagger Docs in ZF2 with Examples - Part 1: Setup and Annotations

Abhinav Singh's Blog: Get real time system & server load notification on any IM using PHP and XMPP

ProDevTips.com: PHP Doctrine - adding automatic, simple CRUD


Community Events











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


security package overview language series symfony2 podcast facebook framework install hhvm introduction opinion component release code composer hack unittest application

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