Geeks With Blogs
A Curious Mind #tastic

I am going to clarify the difference between the Factory Method pattern and the Abstract Factory pattern as described in the Design Patterns book.

Most of this post was stolen from http://www.c2.com/cgi/wiki?AbstractFactoryVsFactor...

According to Anonomyous Genius the main difference is that the Factory Method uses inheritance to solve the problem and the Abstract Factory uses composition. Hanspeter Heeb adds that the Factory Method(FM) pattern is a more basic pattern than the Abstract Factory(AF) pattern and that in fact the AF pattern almost always uses the FM pattern in its implementation. Heeb then states that the AF pattern adds two concepts to the FM pattern.

  • Assign the responsibility for creating objects that belong together to one class.
  • Define a basic abstract type, so that the program can decide on the fly, which special set of objects to produce.

[End Theft]

Ok, so that does clear up quite a bit for me. The FM pattern is all about defining a contract for the creation of a given type of classes. And the AF pattern is about choosing which FM is going to be executed. This is a great (even if it is a bit murky at first) example of Seperation of Concerns where the FM is, again, all about actually making the thing and the AF is about which thing we are going to make.

Posted on Monday, August 21, 2006 8:13 PM | Back to top


Comments on this post: The Factory Pattern: Abstract or Method?

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Dru Sellers | Powered by: GeeksWithBlogs.net