• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clarification regarding GoF - Creational Patterns

 
Srinivasa Kadiyala
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a bit confused of the difference between a Abstract Factory Pattern and Factory Method pattern.

Appreciate if any one can give me a brief clarification on the difference or point me to a place where I get a good clarification.

Thanks in advance.
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abstract factory (AF) : Defines an interface for creating families of objects without mention there concrete classes.

usage: 1 tablet per day. Oops. That is not for abstract factory. This is: AF encapsulates how objects are created. You don't know what implementation the AF is returning. So it is used when you want to change the objects implementation without affect clients of the object.


factory method (FM): Define an interface for creating an object, but let the subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses.

usage: the concrete creation for an object O is in subclasses Sb, while the object O is probably used in the super class Sp. You use this pattern when you want to utilized inheritance and polymorphism of OO Design: The method M() that uses the created object O is in super class Sp, while the object O's creation is in sub class Sb. Client C use sub class Sb to do the work (C knows Sb) while the method M() that client is using is in super class Sp. Now, DO you understand?! If you can't, try hard, just like this:
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinivasa,

You may also check this blog entry , it explains AbstractFactoy pattern in quite a bit detail. It may be useful to you...

http://dranilev.blogspot.com/2011/02/going-technical-abstract-factory.html

Thanks!
Ranil
 
Srinivasa Kadiyala
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ranil and Bigwood
 
raghuram gannavarapu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinivasa,
In one line, Abstract Factory pattern is One more level of abstraction when compared to Factory Pattern.

Thanks,
Raghuram G
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic