Meaningless Drivel is fun!
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 REST with Spring (video course) this week in the Spring forum!
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: 17257

Sounds like you need a Factory.

An IDE is no substitute for an Intelligent Developer.
wood burning stoves
subject: How to instantiate different object
It's not a secret anymore!