MVC-MVP-MVVM-MVI

Small order

The framework is oriented to the reuse of a series of codes with the same behavior, while the design is oriented to the reuse of a series of codes with the same structure. In short: the framework is great wisdom, used to divide the software design; design mode is a small skill, to propose solutions to specific problems, in order to improve code reuse rate and reduce coupling.

Attitude towards the evolution of the framework: The so-called truth is nothing more than a dogmatic theory established under the conditions of a specific field.

MVC

Model-View-Controller (Model-View-Controller)
MVC是一种框架模式而非设计模式,GOF把MVC看作是3种设计模式:观察者模式、策略模式与组合模式的合体,而且其核心在观察者模式,也就是一个基于发布/订阅者模型的框架。

Classic MVC

It was first proposed by Trygve Reenskaug on the Smalltalk-80 system in 1978.
The essence of MVC is layered decoupling, separating the presentation layer and logic.

  • **Model: **Model can be an independent object or a collection of a series of objects.
  • **View: **View is the visual manifestation of some important data in the Model.
  • **Controller: **Controller is used to connect User and System. For example, when the Controller receives the user's output, it will convert it into an appropriate event message and pass the event message to one or more Views.

Application Model MVC

Model2

In 1998, Model2 was first proposed.
Model2 is used in Web development, and JavaBean, JSP, and Servlet correspond to the three parts of MVC. Model2 improves the flow of events.
User --> Controller --> Model --> Controller --> View --> User
View and Model are no longer coupled, and are close to MVP. The difference is that MVP captures user interaction requests instead of the Controller.

MVP

Model-View-Presenter (data layer-UI layer-business logic layer)

MVVM

Model-View-ViewModel
was proposed by Microsoft's WPF and Silverlight architect John Gossman in 2005, and was used in Microsoft's project development. Its predecessor was the Presentation Model (PM) design pattern published by Martin Fowler in 2004.

DataBinding

Configuration

android {
    dataBinding {
        enabled true
    }
}

Layout structure

First, the root node is layout; secondly, the data entity class used in the layout file's reputation; and then the traditional layout node.

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <!--data节点声名数据模型-->
    <data>
        <variable
            name="userModel"
            type="com.test.demo.testdemo.UserModel" />
    </data>

    <!--传统布局-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <Button
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="@{userModel.btnText}" />
    </LinearLayout>
</layout>

Data binding

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    
    
    super.onCreate(savedInstanceState);
    DataBindingTestBinding binding = DataBindingUtil.setContentView(this, R.layout.data_binding_test);
    UserModel model = new UserModel();
    model.setBtnText("中国");
    binding.setUserModel(model);
}

MVI

Model-View-Intent (data layer-UI layer-business logic layer)

  • **Model: ** represents a state.

Guess you like

Origin blog.csdn.net/u010019244/article/details/113276363