News Feed
Sections




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

Pádraic Brady's Blog:
The Factory and Abstract Factory patterns in PHP
June 22, 2006 @ 07:25:51

Recently, Pádraic Brady had to explain some of the design patterns, specifically the Factory and Abstract Factory patterns, to someone (or a group of someones) in his day to day business. To help make it easier for other people out there looking for the same information, he's posted what he said on his blog today.

First, he talks about the Factory pattern:

At some point in developing, developers will discover a need to support switching among various methods of performing an action. The example I used in a forum post earlier was Database Abstraction. Say for a moment you want to separate all the logic needed to create an Abstraction object (say using ADOdb Lite) into a central place for easier control. At this point the Factory Pattern starts rearing its head.

Of course, a bit of sample code is given to illustrate the point, creating the instance of an ADOdb object.

Next up is the Abstract Factory pattern - the difference being that these make it easy to switch between Factories using different resource (such as his example to switch between ADODB and PDO).

In these cases, we will have multiple Factories. However instead of one generically named Factory, we will have several specific Factories. This should (eventually) lead us to impose a parent class, which will allow duplicated code from each specific DatabaseAbstractionFactory to be moved up to the common parent class.

Just as before, they provide example code to illustrate the use of this slightly different pattern.

1 comment voice your opinion now!
factory abstract pattern tutorial example explaination factory abstract pattern tutorial example explaination


blog comments powered by Disqus

Similar Posts

WorkingSoftware.com.au: Configuring PHP4 and PHP5 to run concurrently on FreeBSD

IBM developerWorks: PHP encryption for the common man

Community News: Symfony Framework Makes Some Updates (v.0.6.2 and Content)

Vanessa Vasile's Blog: Using PHP to Perform DNS Lookups

Thomas Weinert: Carica Chip 101 - Controlling An LED With PHP


Community Events





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


install deployment laravel voicesoftheelephpant release bugfix package unittest library podcast community series opinion interview introduction framework api symfony language zendserver

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