Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

AbstractFactory  RSS feed

 
Ranch Hand
Posts: 36
  • 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: 8980
168
  • 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.
 
If you're gonna buy things, buy this thing and I get a fat kickback:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!