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:
Overriding Strategy Logic - The Template Method Pattern
September 25, 2012 @ 08:58:01

On PHPMaster.com there's a new tutorial posted talking about the Template Method Pattern to help make some sense (and make easier to use) your implementation of the Strategy pattern.

This bring us back to the question whether it's feasible to eliminate duplicated strategy logic via Inheritance rather than switching over to plain Composition. Indeed it is, and the clean up process can be conducted through an ubiquitous pattern known as Template Method. [...] Simply put, there's a base class (usually an abstract one), which declares a concrete method (a.k.a. the template) responsible for outlining the steps or hooks of a certain algorithm. Most of the time the base type provides boilerplate implementation for some of those steps and the remaining ones are delegated to subclasses.

The subtypes then override the base's functionality and extend it with their own. They show an example of this by making a jQuery image slider (using this plugin) , an "AbstractCycleSlider" class and two subclasses for two other types - "FadeSlider" and "ScrollSlider", each outputting their own HTML. It also shows how to implement a slider using a different plugin and output both in the same script.

0 comments voice your opinion now!
strategy logic designpattern template method abstract subtype


blog comments powered by Disqus

Similar Posts

The Bakery: Some ideas to organize your CSS files and autoload them in CakePHP

DevShed: Developing an Extensible Template Processor in PHP 5 (Part 1)

Sameer Borate's Blog: Templating with Haml

ProDevTips: Writing a CMS/Community with Smarty and the Zend Framework: Part 8

PHPBuilder.com: Exploring PHP Design Patterns


Community Events





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


podcast deployment series symfony release community tips language framework threedevsandamaybe zendserver code api bugfix developer development laravel list interview introduction

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