• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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: 9239
177
  • 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!