 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
PHPImpact Blog: Static Factories vs Public Constructors
by Chris Cornutt 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.
voice your opinion now!
static factory designpattern constructor object instance
Bill Karwin's Blog: ActiveRecord does not suck
by Chris Cornutt May 29, 2008 @ 17:07:50
Bill Karwin (formerly of Zend and the Zend Framework project) has a new post to his blog defending one of the more abused (both in code and in opinions) design patterns, ActiveRecord:
ActiveRecord is fine. It is a tool that does just what it's designed to do. What sucks is when developers try to make it do other things than what it's intended to do.
He cites his work with the Zend_Db component and how Mike Seth gets it right when he says that the pattern shouldn't be "ActiveRecord-View-Controller". He compares the ideas of a true Model in an MVC application with the incorrect ideas that many developers seem to hold.
A Model is a class that provides a logical component of your application domain. Models are products of OO design, which is a development activity I see get very little attention in the developer blogosphere or the developer tools market.
Models can reference one or many (or no) database tables and are not where the hard work is being done. That's saved for the ORM (or ActiveRecord) to do.
voice your opinion now!
activerecord designpattern modelviewcontroller mvc model orm
SitePoint PHP Blog: What's so bad about the Singleton?
by Chris Cornutt February 13, 2008 @ 12:13:00
On the SitePoint PHP Blog today Troels Knak-Nielsen asks th3e question "what's so bad about the singleton?" For all of its advantages, is there a darker side of the design pattern when it pertains to global variables.
As I have often taken this stance myself, I found it reasonable that I should be able to argue for it, so I'll try to give an explanation. This is also in part a follow-up on my post from last week, in which I present a way to avoid global symbols, without spending much time on why.
He talks about what they are and how they're commonly used - sometimes with some unpleasant side effects because of their use of globals.
voice your opinion now!
singleton designpattern global sideeffect static
Michael Girouard's Blog: One Step Closer to an Abstract Singleton
by Chris Cornutt November 27, 2007 @ 09:37:00
Michael Girouard has pointed out that things in the PHP world are one step closer to being able to create an abstract Singleton object via a simple script he's shared.
The singleton is an incredibly useful pattern in PHP for many reasons. I tend to find myself using them when I know I should be using static classes, but can't because of PHP's lack of proper class name discovery in extended static classes.
[...] And that works like a charm every time. The problem is, in one application there may be several classes that need to be singletons. In which case my first thought was to build an abstract singleton.
Unfortunately, it didn't quite work like he'd thought it would. He did, however, come up with something that did work - creating an interface and making an abstract implementation of it (code example for this included).
voice your opinion now!
abstract singleton designpattern implements interface abstract singleton designpattern implements interface
|
Community Events
Don't see your event here? Let us know!
|