I ran into a question on stackoverflow the other day that sort of shocked me.  It was a piece of code, with the author asking why it wasn't a factory pattern.  The thing that shocked me was that the pattern that everyone was agreeing was a factory method pattern, really wasn't. I’m pretty sure that this a rare occurrence for stackoverflow, they seem to have an abundance of gifted developers who love to answer questions.  Regardless, here is my proverbial kick at can, trying to explain the differences as clearly as I can.   (BTW, if you're looking for a different take on patterns, I'd recommend the Head First Design Patterns book, which I thought provided a pretty good introduction into patterns, in way that doesn't put you to sleep.)

For this post, I simply want to discuss three factory designs: the Simple Factory, the Factory Method Pattern, and the Abstract Factory Pattern.  But instead of concentrating on learning the patterns (you can find all these and more at  dofactory ), I’m going to concentrate on what I see as the key differences between the three, and how you can easily recognize them.

As a bit of background, the thing that all three have in common is that they are responsible for creating objects.  The calling class (which we call the “client”) wants an object, but wants the factory to create it. I guess if you wanted to sound really professional, you could say that factories are used to encapsulate instantiation.

So what's the difference between a simple factory, a factory method design pattern, and an abstract factory?

Simple Factory

The easiest way for me to remember this is that a simple factory is called directly by the class which wants to create an object (the calling class is referred to as the "client").  The simple factory returns one of many different classes.  All the classes that a simple factory can return either inherit from the same parent class, or implement the same interface.

Step One:
you call a method in the factory.  Here it makes sense to use a static method.  The parameters for your call tell the factory which class to create.

Step Two:  the factory creates your object. The only thing to note is that of all the objects it can create, the objects have the same parent class, or implement the same interface.

Step Three: factory returns the object, and this is why step two makes sense.  Since the client didn't know what was going to be returned, the client is expecting a type that matches the parent class /interface.

Sticklers will note that this is not an “official” design pattern. While this is true, I find it useful and think that it merits discussion!

Factory Method
The official definition of the pattern is something like: a class which defers instantiation of an object to subclasses.  An important thing to note right away is that when we're discussing the factory pattern, we're not concentrating on the implementation of the factory in the client, but instead we're examining the manner in which objects are being created. 

In this example the client doesn't have a direct reference to the classes that are creating the object, but instead has reference to the abstract "Creator". (Just because the creator is abstract, doesn't mean this is the Abstract Factory!).  It is a Factory Method because the children of “Creator” are responsible for implementing the “Create” method. Another key point is that the creator is returning only one object.   The object could be one of several types, but the types all inherit from the same parent class.

 Step One: the client maintains a reference to the abstract Creator, but instantiates it with one of the subclasses.  (i.e. Creator c = new ConcreteCreator1(); )

 Step Two: the Creator has an abstract method for creation of an object, which we'll call "Create".  It's an abstract method which all child classes must implement.  This abstract method also stipulates that the type that will be returned is the Parent Class or the Interface of the “product”.

Step Three: the concrete creator creates the concrete object.  In the case of Step One, this would be "Child Class A".

Step Four: the concrete object is returned to the client.  Note that the client doesn’t really know what the type of the object is, just that it is a child of the parent.

Abstract Factory

This is biggest pattern of the three.  I also find that it is difficult to distinguish this pattern from the Factory Method at a casual glance.  For instance, in the Factory Method, didn’t we use an abstract Creator?  Wouldn’t that mean that the Factory Method I showed was a actually an Abstract Factory?  The big difference is that by its own definition, an Abstract Factory is used to create a family of related products (Factory Method creates one product).

Step One:
  the client maintains a reference to an abstract Factory class, which all Factories must implement.  The abstract Factory is instantiated with a concrete factory.

Step Two: the factory is capable of producing multiple types.  This is where the “family of related products” comes into play.  The objects which can be created still have a parent class or interface that the client knows about, but the key point is there is more than one type of parent.

Step Three: the concrete factory creates the concrete objects.

Step Four: the concrete objects are returned to the client.  Again, the client doesn’t really know what the type of the objects are, just that are a children of the parents.

See those concrete factories?  Notice something vaguely familiar?  There using the Factory Method to create objects.

So, being as brief as I can:
- A Simple factory is normally called by the client via a static method, and returns one of several objects that all inherit/implement the same parent.
- The Factory Method design is really all about a “create” method that is implemented by sub classes.
- Abstract Factory design is about returning a family of related objects to the client.  It normally uses the Factory Method to create the objects.



04/30/2010 05:43

This is the best explanation I got on the differences between the patterns on the net. Simple and to-the-point.


01/07/2013 17:58

Indeed this makes my concept clear on factory pattern. Another <a href="http://javarevisited.blogspot.com.br/2013/01/difference-between-factory-and-abstract-factory-design-pattern-java.html">difference between Factory and abstract Factory pattern</a> is that, later is used to create factory which int turns create items.

02/02/2011 23:31

Very correct,this is truly very convincing

Manju Sandhu
02/02/2011 23:32

Very precise and nicely described the exact difference in these patterns

04/04/2011 13:29


I applied the Simple Factory on one of my Projects and I still do not understand where does the PizzaStore come in on your UML Diagram.

Can you edit your graphic to accommodate the sample from the HFDP book? ^_^


08/08/2011 10:00

Great explanation. thanks a lot!!!

03/11/2012 18:35

You are so awesome! I cannot thank you enough for this!

03/19/2012 06:16

Very good and comprehensive explanation. The interesting point is that there is no code samples but still everything is absolutely clear.

04/03/2012 08:47

Very good explanation of the difference b/w the three patterns

06/20/2012 18:36

I would like to thank you for the articles you are writing.the content is good, and you’re an educated writer unlike most of the blogs I come across when searching on this topic.

06/20/2012 18:44

I enjoyed your blog. It’s easy to read,The post is quite neat and every word is so simple that is easy to understand. That’s one actually nice post.

06/26/2012 10:02

Thanks for this article. Though it's good but somehow I am not able to judge, when should I use 'Simple factory' and when should I use 'Factory Method' ?

Please help me understand.

09/04/2012 05:21

Thanks, Article isv ery precise and nicely described the exact difference in these patterns, If you add one small example for each pattern then it would be more better to understand.

persian Man
09/11/2012 05:54

thank you!

Manish Patwa
09/17/2012 05:21

This is awesome example!!! I loved it.
Thanks a ton Corey!

11/21/2012 23:01

Really, very simple and helpful. But I need a simple real world example that describes difference

Jonas Pettersson
12/10/2012 00:23

Hi, I must say "Good Job".

I am reading a course in Design Patterns at a swedish University and though i have the book "Heads First Design Pattern" book you mentioned your explanation is still superior to that of the book.

Thank you!

01/30/2013 19:21

This is the best explanation I got

02/08/2013 01:46

As you said, Head First Design Patterns is damn useful for a newbie (or anyone struggling with the basics of a pattern), but this article has helped me over and over again when trying to remember the differences of the different factories, thanks!

thanks Corey, for the very clear differences!!
02/16/2013 23:10

03/12/2013 10:52

It precisely answers my questions/doubts about simple-factory & factory-method pattern, good Job.

03/18/2013 10:33

Thanks man! kool

Jiten Shah
03/27/2013 07:24

thanks a lot. very simple explanation.

04/14/2013 23:31

Superb, a very neat explanation. Thanks for your effort.

05/24/2013 06:12

Simple but most effective!! Must for everyone.

05/30/2013 03:14

Good explanation. But 1 very serious doubt.
As per my understanding factory method is for return the subclass object( product ).
In you explanation about factory method, in step 1, you mentioned as Creator c = new ConcreteCreator1(); . And the creator is having an abstract method as 'Create()'. Since you call new ConcreteCreator1(), the object of ConcreteCreator1 is already created, then why we need a 'Create()' method?
Please clarify my query..

06/02/2013 23:49

hear 'Creator c' is a factory and 'Create()' is a method to create different products.

Creator c = new ConcreteCreator1() -- This a factory instance
c.Create()--> return new Product();

06/02/2013 23:44

Really very simple explanation about the differences between the patterns

06/09/2013 23:16

Thank you so much for this easy to understand concept. I was so confused before reading this article.

06/26/2013 21:18

Thank you for explanation. Now I can see the difference between factory method and abstract factory.

07/20/2013 20:40

Extraordinary Thanks a lot

07/25/2013 05:08

Thanks.. it was great explanation

Jack paul
08/13/2013 23:43

very nice post.

10/04/2013 08:53

Thanks man...really helped in understanding difference between these factory patters

10/11/2013 04:46

Very well explained. Bang on the confusions I have had on factory method and abstract factory. Thanks a ton

11/12/2013 01:46

Very Nice article.

It inspired me to create blog (http://simpledesignpatterns.blogspot.co.il/) and explain this three patterns too (http://simpledesignpatterns.blogspot.co.il/2013/11/factory-family.html)

Thanks for inspiration!

01/29/2014 06:44

very nice. the best explanation i have seen. thank you so much.

02/03/2014 02:46

one word --> Excellent !

04/05/2014 23:32

Thanks for your clear explanation on these three related design patterns.


Leave a Reply


    I'm a .Net developer, currently living in Montreal.  I've been a developer most of my life, and have been lucky enough to make a living it our of it for the past 7 years.


    June 2009
    May 2009


    Design Patterns
    Net Svn

    RSS Feed