Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to instantiate different object

 
amit sharma
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you need a Factory.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic