• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

How does one usually make a Factory choose between multiple Impl classes?

I need to make a Factory choose between multiple Impl classes and I would like to know what the best practice is for this? How does one typically pass the data from a class to the ImplFactory in order to choose the appropriate Impl for that class while still maintaining good design principles?

--
I would prefer a thoughtful conceptual answer. No quick posting or links please.
0
Eindoofus
Asked:
Eindoofus
  • 4
  • 2
1 Solution
 
CEHJCommented:
The best practice would probably be

a. use a configuration file
b. put the name of the impl class in it
c. make the factory load it

That way, no recompilation is necessary in order to change impl
0
 
CEHJCommented:
If that seems like overkill (could be for just one class) then the following is good
java -Dimpl.class=foo.bar.SomeImpl YourApp

Open in new window

0
 
EindoofusAuthor Commented:
Could you please elaborate a bit more on "b" and "c"? I'm having a hard time understanding them. If you have any code as an example I would greatly appreciate it.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
I'm going to abandon my first suggestion if favour of my second - unless you have several classes that have to be selected
0
 
EindoofusAuthor Commented:
1:
java -Dimpl.class=foo.bar.SomeImpl YourApp

Open in new window


I'm not sure if we are on the same page. Can you please take a look at my other question to see what I am doing:

http://www.experts-exchange.com/Programming/Misc/Q_27390758.html


0
 
CEHJCommented:
:)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now