MVC, MVP and MVVM are 3 common paradigms applied to develop an application that is easy to combine, easy to test, and easy to maintain. But not everyone can understand them well. Let’s learn about the 3 models of MVC, MVP and MVVM.

What is MVC?

MVC has 3 components: Model – View – Controller

This model includes 3 main components: Model – View – Controller. MVC is a fairly popular software architecture model today. Each component will take on a separate task and operate independently of the other components.

Viewing: What is Hmvc

The software is developed based on the MVC model:

Laravel is a free and open source PHP framework, built to support the development of software and applications, following the MVC architecture. Currently, Laravel is the most popular and best PHP framework.

Symfony is an Open Source framework built on the PHP5 programming language, helping to develop personal website design. What are the strengths of Symfony? Currently, Symfony is very popular thanks to two great advantages, namely: a large community of users and programmers and a reliable structure, freedom of deployment.

MVC, MVP and MVVM – What are the components of MVC

? Specifically as follows:

Model

This is the component that manages all of the application’s databases. The Model also contains classes that describe the business logic and define business rules for the data (how the data will be changed and used).

View

View is the display interface for the user. This is where the user will perform query, search, .. data operations. This section represents UI elements (eg: XML, HTML, …). The View interacts with the Model through the Observer pattern.

Controller

Controller is the part that has the function of recording and navigating the requests (requests) that the user makes at the View. After receiving, the Controller will process the data through the Model and finally return the results and feedback at the View.

MVC, MVP and MVVM – How MVC works

?3 Model – View – Controller parts of the MVC model interact with each other to form a triangle. The way this model works and flows can be understood simply as follows:

READ MORE  What is Product Identification?

First, through the View, the user will make requests (user requests). Controller then acknowledges these requests and continues to send them to the Model for processing. When the data has been processed. ,Controller will notify the View. And the View will directly get data from the Model to display on the UI interface with visual formats such as HTML, XML, JSON, … so that users can understand.

Thus, through the above operation model, we can see that the method (method) to handle the user request is decided by the Controller. The method of handling data (UI logic) to display on the View is decided by the Model. The View only has the function of receiving user requests and displaying the final data.

What are the advantages of MVC

?The MVC model has many advantages, such as:

Light, bandwidth saving: MVC does not consume much viewstate, so it saves bandwidth. The operations of sending and receiving data are happening continuously. Therefore, the website/application works more stably. The software can be checked and detected easily. It is very good at separating the Model and View parts. The model has a simple structure. Even if you are not too technical, you can use it.

What are the disadvantages of MVC

?Besides advantages, MVC also has some disadvantages as follows:

Unit testing is difficult because Controller and Android API are closely related. Controller and View are related. Therefore, when you change the View, you will have to change the Controller. Over time, the Controller will become difficult to control as more and more code is written. MVC is only suitable for projects. big. For small projects, this model is quite cumbersome and time-consuming in transferring data.

MVC, MVP and MVVM – What is MVP?

MVP is an acronym for Model – View – Presenter

MVP is a programming architecture model similar to MVC. MVP has many points inherited from MVC but Controller is replaced by Presenter. This model consists of 3 main parts, including:

MVC, MVP and MVVM – What is the structure of MVP

?Model

Like MVC, Model includes classes that describe business logic and define business rules for data.

READ MORE  Real Time Real Time

View

The component that the user can directly interact with, send requests. View does not include any logical processing.

Presenter

Presenter acts as middle-man. This part will receive user input through the View, process the data with the help of the Model and finally return the result back to the View. Presenter and View communicate with each other through interfaces.

See more: What is a Showroom – Which industry needs a Showroom

MVC, MVP and MVVM – How does MVP work

?In the MVP model, the View is the only layer that interacts with the user (unlike MVC, both View and Controller layers have interaction can be recorded). The flow of this model is as follows:

View receives user interaction. Then love The request is passed to the Presenter and processed through the Model. When the Model makes changes and processes the data, the Presenter gets the data from the Model to transmit to the View.

What are the advantages of MVP

?The outstanding advantages of MVP can be mentioned as:

MVP has a clearer code structure than MVC, so it is quite easy to understand and use. It is easy to write unit tests for Presenter because it works independently of View and is not tied to any Android API.

What are the disadvantages of MVP

?The biggest disadvantage of the MVP model is that over time, the Presenter will gradually grow up due to more scattered business logic. It will be difficult for users to control and split the code when the Presenter is too big.

MVC, MVP and MVVM – What is MVVM?

In MVVM, Controller is replaced by View Model

MVVM (Model – View – ViewModel) is a model that supports two-way data binding (data binding) between View and ViewModel.

MVC, MVP and MVVM – What is the structure of MVVM

?This model includes the following main components:

Model

Like the MVP and MVC model, the Model in MVVM is the part that represents the business logic layers, defining the business rules for the data.

READ MORE  Affiliate Marketing

View

This is a place that allows users to interact and make requests.

View Model

This is an intermediate layer between View and Model and is considered as a replacement for the Controller in the MVC model.

MVC, MVP and MVVM – How MVVM works

?In MVVM model, ViewModel is the place to do almost all business logic, manage methods, other properties to maintain viewstate . This means that the View becomes a mapping that exposes the ViewModel’s state at all times.

Note, in MVVM, the layers below will not know the information and data of the upper layer. This helps to provide a clear separation between the user interface and application logic.

What are the advantages of MVVM

?The biggest advantage of MVVM is that users can easily perform unit testing because they do not have to depend on the View. When testing, you don’t need to create mockup like MVP model, you just need to validate the appropriate observable variable.

What are the disadvantages of MVVM

?MVVM has a maintainability disadvantage. When assigning variables and expressions to the View, the scattered logic will increase over time. This makes it more difficult to control and add code.

When to use MVC, MVP, MVVM pattern?

You should use MVVM when you can bind data through DataContext

What is the reason to use the MVC, MVP and MVVM pattern?

You should use MVP if it is not possible to bind data via DataContext (eg Windows Forms).

The MVVM model should be used in cases where data can be bound via DataContext (eg: WPF, javascript using Knockout).

See also: What is Capitalization – What is Market Cap

And MVC should be used when the connection between the View and the rest of the application is not always available (eg web API). At that time, you cannot use MVP or MVVM effectively and must choose the MVC model.

Through the article of “Mat Bao – the best Cloud Server rental service provider” provided, each model has its own advantages and disadvantages. Depending on each specific case, you need to consider to choose the most suitable model. Good luck!