News Feed
Sections




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

PHPImpact Blog:
Static Factories vs Public Constructors
July 18, 2008 @ 12:58:31

On the PHP::Impact blog Federico Cargnelutti has posted a comparison of using static factory methods to create an instance of a class versus making an object, calling the constructor.

Normally, creating an instance of a class is done by calling new, which calls the constructor. Static factory provides a static method that returns an instance of the class. So, you are using static factory instead of the constructor. Providing a static factory method instead of a public constructor has both advantages and disadvantages.

He includes some of the advantages of the factory method and others for the normal call to create an object. He also mentions some comments made by Dagfinn Reiersol in a blog post about public constructors.

0 comments voice your opinion now!
static factory designpattern constructor object instance


blog comments powered by Disqus

Similar Posts

Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 9)

Pádraic Brady's Blog: The Factory and Abstract Factory patterns in PHP

WebSpeaks.in: Learn Simple Method Chaining in PHP

Paul Reinheimer's Blog: Object-Oriented PHP, Concepts, Techniques, and Code

Amazon Web Services PHP Blog: Provision an Amazon EC2 Instance with PHP


Community Events





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


symfony voicesoftheelephpant podcast deployment release library introduction tips bugfix series developer list community interview laravel api zendserver language framework conference

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