There is no Factory…
WUT??? Yes! There is no Factory! Actually there is no Factory Pattern. WHY? Because developers are talking all the time THE Factory Pattern (GoF). But there is no such pattern. There are two Factory-related patterns:
Abstract Factory (GoF):
Provide an interface for creating families of related or dependent objects without specifying their concrete classes… That means usually you have an abstract factory class and concrete implementations of that. HeadFirst Design Patterns (http://goo.gl/KA6k5) lays out a good example for that: There’s an abstract Pizza-Factory that can create pizzas. There are two different Styles available: regular with fingerthick dough and chicago-style which is pretty flatt. Still the procedure for creating the pizza is mainly the same but uses different ingrediants resulting in a specialized dough. So there are two concrete factory implementations to produce the pizzas as desired. It is not one class creating all sorts of objects…
Factory Method:
The factory method is just a way to create new objects of a class via calling a (most often static) method like CreateInstance() which is directly defined on the class. The constructor is set to private and there you go. Resharper even offers a refactoring “Replace Constructor with Factory Method”. It often looks like this:
public class MyObject
{
private MyObject() { /* blocked */ }
public static MyObject CreateInstance()
{
return new MyObject();
}
}
There you go…


