Re: Difference between Factory and Abstract Factory



Responding to EvilOldGit...

I've read the gang of four, and various things I've googled, but I'm
just too stupid to really get the difference between a factory and an
abstract factory.

The difference lies in how dynamic the substitution needs to be. In both cases the Product and the Factories to produce them are generalizations. The difference is that in Factory Method the subclasses in each generalization map 1:1 to each other while in Abstract Factory the Factory subclasses map 1:* to Product subclasses.

Thus in Factory Method a concrete factory object can instantiate exactly one flavor of one Product. But in Abstract Factory a single concrete factory object can instantiate a different flavor of Product from each of multiple Product generalizations. IOW, one uses Factory Method when there is only one family of products and one uses Abstract Factory when there are construction similarities across multiple families of products.


*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl@xxxxxxxxxxxxxxxxx
Pathfinder Solutions
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
"Model-Based Translation: The Next Step in Agile Development". Email
info@xxxxxxxxxxxxxxxxx for your copy.
Pathfinder is hiring: http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH



.



Relevant Pages

  • Re: Access subclass attributes from base
    ... factory object with the interface described earlier that implements more than ... The Instance property is the factory method that utilizes ... The subclasses only responsibility is to tell the base class to which ... super-generic base class contain it all. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: using jMock with components
    ... >> chance to mock it. ... Whilst running normally the factory class returns ... > but don't worry about Abstract factory it is a valid approach. ... >> I created a factory interface which exposed the components I needed to ...
    (comp.lang.java.programmer)
  • Re: Difference between Factory and Abstract Factory
    ... abstract factory. ... Cat * MakeTheKittah{ ... An Abstract Factory as far as I can see is simply a factory method ...
    (comp.object)
  • Re: Difference between Factory and Abstract Factory
    ... abstract factory. ... these are like Abstract Factory and ... Factory Method respectively. ... Override methods like createThing() *in the factory*. ...
    (comp.object)
  • Re: using jMock with components
    ... Whilst running normally the factory class returns ... Usually its fine to have the createXXXComponent method on the abstract factory itself, which internally just delegates to the concrete factory. ... The reason I created the two factories is so I can omit the mock factory when I make a distribution. ... with the interface and merge the abstract and real factory classes together and create a getComponentmethod which creates a newInstance of the class using reflection, and have the test factory override that method. ...
    (comp.lang.java.programmer)