aspose file tools*
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
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "How to instantiate different object " Watch "How to instantiate different object " New topic

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: 15641

Sounds like you need a Factory.

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: How to instantiate different object
Similar Threads
difference between factory pattern , abstract factory pattern and command pattern
Interview Question & help in Vector,HashMap & ArrayList
Builder Vs Factory