my dog learned polymorphism
The moose likes OO, Patterns, UML and Refactoring and the fly likes How to instantiate different object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "How to instantiate different object " Watch "How to instantiate different object " New topic
Author

How to instantiate different object

amit sharma
Ranch Hand

Joined: Jul 19, 2006
Posts: 129
I have different commands. I make interface with method execute. I make 5 concrete class which implements command interface. This concrete class instantiate in different ways. some require 1 parameter, some require 2. What is the best way to design a class which takes TypeofCommand as input and instantiate correct class so that client can then simply call execute method. TypeofCommand can contains information about which class to instantiate.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17149
    
  27

Sounds like you need a Factory.


An IDE is no substitute for an Intelligent Developer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to instantiate different object
 
jQuery in Action, 3rd edition