This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

AbstractFactory  RSS feed

 
Ranch Hand
Posts: 38
  • 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: 10128
214
  • 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!