• Post Reply Bookmark Topic Watch Topic
  • New Topic

AbstractFactory  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Below shape is an interface and circle and triangle are implementation
Likewise  color is an interface and it's implementations

AbstractFactory is class which will create an instance of class depending data passed by user

For example

If (name.equals("circle"))
       new Circle();

Q)I was asked in an interview can you create object using reflection here instead of hard coding?

And)Class .forename(circle).new instance();

He was not satisfied.

Please correct my answer if it was wrong?


AbstractFactory
Shape get shape(String name)
Colour get colour(String name)


Shape factory                   ColourFactory  abstract

Shape (I)                                color (I)
  Circle    Triangle                   Red Green
 
Saloon Keeper
Posts: 8097
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure the interviewer intended for you to use one of the factories.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!