Architectural Patterns MVC MVP MVVM

  • Link to this article: https://blog.csdn.net/followYouself/article/details/125948790

1. Flowchart

insert image description here

1.1 MVC and MVP

  1. Disadvantages of MVC. View and Model may be directly coupled. View can directly request data through Model, and Model data changes can also be directly notified to View. MVP and MVVM solve this problem, and View and Model are completely decoupled.
  2. The communication between View and Model in MVP must go through Presenter.
  3. MVC's Controller and MVP's Presenter both handle a large amount of business control logic, and the code is relatively complex.

1.2 MVVM

  1. The important idea of ​​the MVVM pattern is the two-way binding of data (Model) and View to achieve automatic updating of both.
  2. Compared with MVP, MVVM has two-way binding between the View and ViewModel layers. Data changes in the ViewModel layer will be directly reflected in the View, and data updates in the View will also be reflected in the ViewModel.
  3. Advantages over MVP. Through the observer pattern and reactive programming, MVVM simplifies the data update logic and reduces the possibility of bugs during data update.
  4. Two-way binding also brings disadvantages, such as increased difficulty in debugging and locating problems.

2. JetPack components

Android JetPack components make extensive use of the MVVM architectural pattern.

2.1 Example

  1. Data Binding
  2. Lifecycle
  3. LiveData
  4. ViewModel
  5. Room

Guess you like

Origin blog.csdn.net/followYouself/article/details/125948790