Home  /  Questions  /  Question

100   96.6
Jul 27, 2010

Factory Method Pattern differs from the one on Wikipedia

The Factory Pattern method mentioned here clearly differs with the one mentioned on wikipedia(http://en.wikipedia.org/wiki/Factory_method_pattern). e.g. the one on Wikipedia doesn't mention about abstract product at all and the concrete factory class implements a static method & does not require the concrete factory class to be initialized at all. I've seen this kind of implementation in a lot of places e.g. Enterprise Library DatabaseFactory class. The difference looks more than a variation, it's a totally different kind of implementation.

Although, I am more inclined to go that I wanted to know if someone can point out anything I might have missed to prove otherwise.

130   96.7
Jul 28, 2010
Interesting variations. I don’t take a rigid stance on exactly what the formal structure of a factory pattern should be so I’m probably the wrong person to answer this question. Variations exist in all the patterns that I’ve used and each variation exists to solve specific needs. So, if you’re question is purely to receive an acknowledgement that there are variations between these two patterns, then yes you are correct.

Thanks. Apart from checking if there are variations, I wanted to know if both forms are correct or not. The stark difference between the 2 designs, i.e. not requiring to instantiate the Concrete Factory class, made me believe that these are 2 different designs altogether. Also, I couldn't think of an example where I'd need to explicitly create an object of Concrete Class rather than use its static method which return the product class object. Wouldn't it be an efficient design of the two? --- Pankaj Mhatre  Jul 29, 2010
So, I decided to take a closer look at this and briefly what I discovered is that I don't like the Wiki implementation because it leaves concrete dependencies inside the factory itself, where as the GO4 design keeps the factory loosely coupled and follows the Open/Closed Principle, which states that the code should be open for extension, but closed for modification. The factory itself shouldn't need to be modified every time a new concrete class is added. So I think we agree if I'm understanding you correctly. Someone should probably suggest an update to the Wiki. --- Andrew Green  Jul 29, 2010

425   99.9
Aug 08, 2010
Remember that when discussion paterns you need to keep in mind these are ABSTRACT ideas.

When a group of people talk about a building for example they all have differenet visions in their head of a building but can still talk about the build though there vision of the actuall implementation is different and varies.

It allows for the high level discussion.

There is no hard and fast implementation when talking patterns.

Remember it's how to talk about something and work to a implementation.

Like building a house your spouse and you will have differnet ideas of the finished idea until it is done.

:-)  (I've been there)