Pattern MVC:Model-View-Controller


(UCM ELP) #1

Concept

MVC is an abbreviation of model-view-controller which’s a software design pattern. It organizes code with a business data, logic and interface display method. Business logic is aggregated into a single component, and there is no need to rewrite business logic while improving and personalizing the interface and user interaction.

MVC allows us to separate the components of our application depending on the responsibility they have, M refers to the business model, V refers to the user interface, C is the controller. It separates the implementation code of M and V, so that the same program can be used differently. The purpose of C is to ensure the synchronization of M and V. Once M changes, V should be updated synchronously.
mvc

Model

The model represents everything that has to do with data access: save, update, obtain data, plus all the code of the business logic, basically Java classes and part of the business logic.It can also have logic to update controller if its data changes.

View 

A view is an interface that a user sees and interacts with, it represents the visualization of the data that model contains.

Controller 

The controller is responsible for connecting the model with the views, it works as a bridge between the view and the model, the controller receives events generated by the user from the views and directs the model to the respective request.

Advantage

  • Easy maintenance

  • Possibility to add multiple representations of the data.

  • High reusability of large-scale project code.

  • Clear structure and division of labor.

Disadvantage

  • With simple small projects, using MVC design will reduce development efficiency.

  • The amount of files that must be maintained increases considerably.