Friday, April 29, 2011

Is this the command pattern?


I have a MVP Gui and now I would like to define certain Actions or Commands (Modify, Save, Close, ...) for certain views.

Is there an easy way to do this? Should I provide Commands for each View?

From stackoverflow
  • The easiest way is to have a factory where all your command objects are instantiated. So if you have a open Job Command all the views would goto the factory and pull out the Open Job Command object, instantiate it, and then execute it. If you need to fix a bug or change the Open Job Command there only one spot you have to do it for all the Views.

    With that being said there will be some commands that will probably be unique to each View. Despite that you may want to still encapsulate those in a command object as you can easily implement Undo/Redo with everything going through command objects.


Post a Comment