File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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: 17410

Sounds like you need a Factory.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: How to instantiate different object
It's not a secret anymore!