MVC and command pattern

Aman Aggarwal picture Aman Aggarwal · Jun 30, 2010 · Viewed 11.8k times · Source

Ok, this is kinda dumb. I'm trying to wrap my head around the use of the MVC and Command Patterns. The questions basically concern where to place code.

In the MVC pattern, where are the Commands instantiated? Are they created by the Controller, or are they contained fully in the Model or neither.

BTW, Should one be using the Command pattern if there is no need of undo/redo.

Regards

Answer

Garett picture Garett · Jun 30, 2010

While there are many variations based on the needs/complexity of an application, you typically find them implemented in the Controller. Here is a great article on using the Command pattern in an MVC architecture. I'm not sure what type of application you are building, but here are a few more resources that show implementations on different application stacks.

http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html

http://msdn.microsoft.com/en-us/library/ff647590.aspx

http://www.phpwact.org/pattern/model_view_controller