Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC and command pattern

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

like image 447
Aman Aggarwal Avatar asked Jun 30 '10 09:06

Aman Aggarwal


People also ask

What is command MVC?

MVC Commands are used to break up the controller layer of a Liferay MVC application into smaller, more digestible code chunks. Sometimes you'll want to override an MVC command, whether it's in a Liferay application or another Liferay MVC application whose source code you don't own.

What is pattern in MVC?

The Model View Controller (MVC) design pattern specifies that an application consist of a data model, presentation information, and control information. The pattern requires that each of these be separated into different objects. MVC is more of an architectural pattern, but not for complete application.

What is the purpose of command pattern?

In object-oriented programming, the command pattern is a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time. This information includes the method name, the object that owns the method and values for the method parameters.

Is MVC a pattern or framework?

The Model-View-Controller (MVC) is an architectural pattern which separates an application into three main groups of components: Models, Views, and Controllers. MVC is abbreviated as Model View Controller is a design pattern created for developing applications specifically web applications.


1 Answers

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

like image 84
Garett Avatar answered Sep 28 '22 02:09

Garett