3.3. The Model View Controller Pattern

MVC is a design pattern aimed at describing how you can separate your applications and decouple your system. MVC is the three separate sections of an application. Model refers to the domain of the system. This model represents information that will be used by the application. For example, in this system you will have models such as Product, Order, and ShoppingCart. These objects will store all the information related to that section of the problem domain. View relates to the UI and displays the model to the user. An example would be a web page, or a desktop form. As MVC is an architectural pattern, it is not constrained to a particular implementation, framework, or language and can be used to describe how to structure both web and desktop applications. Finally, controller processes requests from the user and updates the model before returning it to the view to display. The controller will have various methods to control what to display. For example, the controller might be called HomeController, with a method called Index that will set up the model for the Index page before sending the rendered page down to the end-user.

When a request comes in, it will hit the controller first. The controller will construct and populate the model. It will then pass the model to the view. The view will then communicate with the model to display the data. The view might also communicate with the controller to process further questions. Figure 3-1 represents the communication and links between the different parts. The solid lines show associations, while the dashed line indicates indirect associations.

Figure 3-1. Model View Controller

By having your application structured in this fashion, you have separated your concerns (as discussed in The Single Responsibility Principle in Chapter 2. This results in more maintainable software.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.34.80