Skip to Content.
Sympa Menu

patterns-discussion - RE: [patterns-discussion] Abstract Factory vs. Factory Method

patterns-discussion AT lists.cs.illinois.edu

Subject: General talk about software patterns

List archive

RE: [patterns-discussion] Abstract Factory vs. Factory Method


Chronological Thread 
  • From: "Bruce Trask" <trask_b AT ociweb.com>
  • To: "Pablo Schor" <pablo.schor AT lobruno.com.ar>, <livingmetaphor AT yahoogroups.com>, <patterns-discussion AT cs.uiuc.edu>
  • Subject: RE: [patterns-discussion] Abstract Factory vs. Factory Method
  • Date: Thu, 30 Oct 2003 21:36:04 -0600
  • Importance: Normal
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/patterns-discussion/>
  • List-id: General talk about software patterns <patterns-discussion.cs.uiuc.edu>

Hi Pablo,
 
The best answer I've found for this is the following post to comp.object from Robert Martin (Uncle Bob):
 
"The difference is the same as the difference between Strategy and
Template Method.  In Strategy we create a whole new class to contain
the polymorphic methods we want to call.  In Template method we put
the polymorhic methods we want to call in our own class, and depend
upon derivatives to implement them.
 
In Abstract factory we create a whole new class to hold the create
methods for the objects we need to create.  In Factory Method we put
abstract methods in our own class to create objects and depend upon
our derivatives to implement them.
 
public class MyAbstractFactoryUser.
{
  public void f()
  {
    MyObject o = MyFactory.createObject();
    o.doSomething();
  }
}
=============
public class MyFactoryMethoduser
{
  public abstract MyObject createObject();
  public void f()
  {
    MyObject o = createObject();
    o.doSomething();
  }
}
==========
 
Abstract factories are a little more flexible, but a little more
complex than Factory methods.  You can change factories at runtime,
but you can't change Factory Method implementations at runtime.
Abstract Factories have to be created by someone, and references to
them have to be available to the users.  Template Methods live in the
using object and are therefore created with it, and always available
to it."
 
Hope this helps,
Bruce
-----Original Message-----
From: patterns-discussion-admin AT cs.uiuc.edu [mailto:patterns-discussion-admin AT cs.uiuc.edu]On Behalf Of Pablo Schor
Sent: Thursday, October 30, 2003 7:11 AM
To: livingmetaphor AT yahoogroups.com; patterns-discussion AT cs.uiuc.edu
Subject: [patterns-discussion] Abstract Factory vs. Factory Method

I've been using the factory pattern for a while, but don't know exactly if
I'm using the Abstract Factory or the Factory Method. They look the same to
me, but what are the differences?



thank you,


Pablo



Archive powered by MHonArc 2.6.16.

Top of Page