Little friends, see this headline, to the mind is not MVC, MVP, MVVM and other familiar words?
First we need to know why we choose the schema mode?
1. Good readability of code
2, the core idea of the framework: decoupling
3. Convenient testing
4, easy to use and maintenance of good
The simplest way to reduce complexity is to separate the responsibilities between different entities. It should follow the principle of single responsibility and there should be only one reason to change it;
Why is it convenient to test?
When an effective test strategy is used to verify that certain implementations are consistent with their specifications, the application is considered testable. These tests allow developers to find and fix errors before they deliver the application to the user device.
Why is it easy to use?
Programmers understand that the fewer code they write, the fewer opportunities for errors, and if the code is confusing, maintenance costs will rise accordingly, and good code can be easily mastered even if a new developer takes over.
Mvc
Model-view-controller is a broad pattern for creating software applications. There are many applications and frameworks that implement this design pattern.
The model layer is where the domain data resides, managing read and write data, and persistent state. Persistence, network code, model objects, and parsers that manipulate data remain here;
The view layer is the face of the application and is the place to be responsible for the presentation (user interface) and to handle user interaction;
The controller layer acts as a binder, the intermediary between the model layer and the view layer (models and views). It changes the model by responding to the actions performed by the user in view and updating the data in the models layer;
So the problem is, if we use MVC to build complex applications, it becomes difficult;
Over time, more and more code is transferred to the controller, making them more fragile and bloated;
Controller is tightly coupled with view, and if we try to change something in view, we have to go back to the controller layer and make the change there, which violates the equalization allocation between the permission features.
Mvp
MVP represents Model-view-presenter; Cocoa's commitment to MVC can be achieved in MVP. It implements a testable and clear view and model layer separation.
The model layer is the same as the MVC models, which manages read-write data and persistent state, and this part is unchanged.
The view section includes views and view controllers, where views delegate user interaction to the presenter layer, and the view in MVP can be foolish and does not contain logic that can query the model.
The presenter layer contains the logic to handle user interaction, its responsibility is to communicate with the model layer, convert the data into a user-friendly format, and then update the view layer.
In MVP, the view controller is considered a subclass of view, not a presenter. The responsibility is distributed between model and presenter, because view does not contain any logic to achieve a balanced feature assignment.
We cannot say that the MVP is a perfect model, or whether it should follow the MVP, without the need to meet the requirements of the application;
MVP is not suitable for simple applications, it will lead to the writing of boilerplate code from the interface to get the view to start working.
MVVM
MVVM: One of the view modes. It stands for Model-view-viewmodel;
ViewModel is the implementation of the observer design pattern, where any changes in the model are represented in the view and ViewModel;
It includes:
Model: Represents the data model consumed by the application. This class declares properties to manage business data in a manner similar to the two designs described above.
View: It is similar to MVP. The MVVM view includes views and view controllers. It simply saves the data and delegates all the content to the model's layer.
Viewmodel:viewmodel as a link between the model and the view. It is responsible for wrapping the model and preparing the observable data needed for the view.
We use MVVM by remembering some important points:
The view layer is stupid and only knows how to render the data.
The controller is ignorant of the model layer.
Model does not understand viewmodel.
ViewModel has model.
View controller has view.
The controller owns the view model and interacts with the model layer through the ViewModel.
MVVM satisfies almost all functions, and the responsibility for the architecture is distributed between ViewModel and view;
One of the advantages of using MVVM is visibility because the view model is independent of the view, so each entity can be tested individually
This mode cannot be used for simple linear screen applications, which could lead to more complex code and difficult to maintain for new developers.
Do you think that's a better model, you old iron?
In fact, in my opinion, these models are very classic and very useful, each model has advantages, but also have limitations;
In fact, a different way of thinking:
With the existing human resources and time resources, how to achieve faster and better requirements, due consideration of how to prepare for late expansion or refactoring, perhaps this is a choice in line with the "National conditions"!
Technology selection, decision-making is not the pros and cons of each technology solution, but the level of your team, the amount of resources, according to the actual situation to choose the most suitable for your current stage of the architecture scheme
What do you think, little friends? Welcome to the bottom of the message Oh, move your finger, pay attention to us!
Android Project Development How do I choose the schema mode?