Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Factory Method

 
Heena Joshi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody can please explain me what is it and when to use it?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose you have a situation in which you have a abstract class and there are three concrete extensions of that abstract class and you want to have a class which according to a parameter will return any one of the concrete implementations.In that case factory comes into picture.Suppose i pass to the factory that i need the class with id = 1 , in that case the factory will create the object of the calss with id =1 using reflection and then return.
 
Heena Joshi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rahul,

can you give me some example.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A nonsense example, but it should be easy enough to understand
Imagine you want your favorite beer, and you're asking for it to a BeerFactory.

 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou kurinosuke - that is a nice example.
this should be helpful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic