This week's book giveaway is in the iOS forum.
We're giving away four copies of Classic Computer Science Problems in Swift and have David Kopec on-line!
See this thread for details.
Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

AbstractFactory  RSS feed

 
Greenhorn
Posts: 29
  • 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: 8734
162
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!