Re: Difference between Factory and Abstract Factory



On 25 Mar 2007 08:47:10 -0700, EvilOldGit@xxxxxxxxxxxxxx wrote:

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.
Help me please...

Unfortunately I think the GOF book was written in Obfusticated Geek
rather than in plain english. I find it muchly confusing myself (so
below is just my interpretation).

As I understand it "Factory Method" is just used to create object of
the same kind (ie. Cats) that have different variations (ie. breeds of
cats). The GOF book refers to Cat as being the Abstract Product and
say RedCatWithFur as the Concrete Product.

Cat * MakeTheKittah( color ) {
Switch( color ) {
case red: return MakeRedCat();
case blue: return MakeBlueCat();
}
}


An Abstract Factory as far as I can see is simply a factory method
that contains many factory methods (in other words its dealing with
abstractions). For example CreateAnimal( int animalType) would
contain factories for MakeCat, MakeDog, MakeRabbit. The GOF book
refers to the CreateAnimal method as being the Abstract Factory, and
the MakeCat, MakeDog etc as being the Concrete Factory.

Animal * CreateAnimal( int type, int color ) {
switch( type ) {
case cat: return MakeTheCat( color );
case dog: return MakeTheDog( color );
}
}

The problem is that they use the term Concrete Factory in one place
and Factory Method in another place which I find confusing.



----------------
AndyW,
Mercenary Software Developer
.



Relevant Pages

  • 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. ... 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)
  • Re: Difference between Factory and Abstract Factory
    ... This is my take on the Abstract Factory. ... I was too lazy to create a concrete factory for every day of the week, ... public string GetDescription() ... class SaturdayMenu: IMenu ...
    (comp.object)
  • Re: abstract factory -- a doubt ?
    ... Factory does prevent violations of OCP. ... Abstract Factory... ... classes which use Tanks and APCs. ...
    (comp.object)