mvc mvvm mvp
思想程序员(Thought Programmer)
Nowadays we have many options when it comes to architecture design patterns. After developing many apps using Model-View- ViewModel (MVVM), Model-View-Presenter (MVP), and Model-View-Controller (MVC), I finally feel qualified to talk about the differences between them. For easier to understand, we can use a simple example like developing a screen to search books in the BookSearch App.
如今,在架构设计模式方面,我们有许多选择。 在使用Model-View-ViewModel(MVVM),Model-View-Presenter(MVP)和Model-View-Controller(MVC)开发了许多应用程序之后,我终于有资格谈论它们之间的区别。 为了更容易理解,我们可以使用一个简单的示例,例如开发一个屏幕来在BookSearch App中搜索书籍。
Let’s begin now…!
现在开始吧!!
MV(X)要领 (MV(X) essentials)
First of all, we need to understand briefly MVC, MVP, and MVVM architecture before dive into them.
首先,在深入研究MVC,MVP和MVVM架构之前,我们需要对其进行简要的了解。
为什么选择模型视图(C或P或VM)? (Why Model-View-(C or P or VM)?)
The aim of these architectures is to separate the responsibilities of visualizing, processing, and data management for UI applications.
这些体系结构的目的是将UI应用程序的可视化,处理和数据管理职责分开。

Their goals are to increase.
他们的目标是增加。
- Modularity 模块化
- Flexibility灵活性
- Testability可测性
- Maintainability可维护性
模型视图控制器(Model-View-Controller)
Or MVC for short is a widely used design pattern for architecting software apps. The pattern was originally designed by Trygve Reenskaug during his time working on Smalltalk-80 (1979) where it was initially called Model-View-Controller-Editor. MVC went on to be described in depth in “Design Patterns: Elements of Reusable Object- Oriented Software” (The “GoF” book) in 1994, which played a role in popularizing its use. The pattern breaks an app up into three components.
简称MVC是用于架构软件应用程序的广泛使用的设计模式。 该模式最初是由Trygve Reenskaug在处理Smalltalk-80(1979)时设计的,最初被称为模型-视图-控制器-编辑器。 1994年,在“设计模式:可重用的面向对象软件的元素” (“ GoF”书)中对MVC进行了深入的描述,它在普及其使用方面发挥了作用。 模式将应用程序分为三个部分。

Model — is responsible for the business logic of the application. It manages the state of the application. This also includes reading and writing data, persisting application state, and it may even include tasks related to data management such as networking and data validation.
模型-负责应用程序的业务逻辑。 它管理应用程序的状态。 这还包括读取和写入数据,保持应用程序状态,甚至可能包括与数据管理有关的任务,例如网络和数据验证。
View — this component has two important tasks: presenting data to the user and handling user interaction.
视图-该组件有两个重要任务:向用户显示数据和处理用户交互。
Controller — the view layer and the model layer are glued together by one or more controllers.
控制器-视图层和模型层由一个或多个控制器粘合在一起。

模型–视图–演示者 (Model–View–Presenter)
MVP is a derivative of the MVC design pattern which focuses on improving presentation logic. It originated at a company named Taligent in the early 1990s while they were working on a model for a C++ CommonPoint environment.
MVP是MVC设计模式的衍生产品,该模式致力于改善表示逻辑。 它起源于1990年代初期的一家名为Taligent的公司,当时他们正在研究C ++ CommonPoint环境的模型。

Although MVP is a derivation of MVC, they do have their slight differences.
尽管MVP是MVC的派生,但它们确实存在细微差别。
Model — The Model represents a set of classes that describes the business logic and data. It also defines business rules for data means how the data can be changed and manipulated.
模型-模型代表一组描述业务逻辑和数据的类。 它还定义了数据业务规则,这意味着如何更改和操作数据。
View — The View is used for making interactions with users like XML, Activity, fragments. It has got nothing to do with the logic that is to be implemented in the process.
视图-视图用于与用户进行交互,例如XML,活动,片段。 它与流程中要实现的逻辑无关。
Presenter — The presenter gets the input from the View, processes the data with the help of the Model, and passes the results back to the View after the processing is done.
演示者—演示者从View获取输入,在模型的帮助下处理数据,并在处理完成后将结果传递回View。

模型-视图-视图模型 (Model-View-ViewModel)
MVVM was originally defined by Microsoft for use with Windows Presentation Foundation (WPF) and Silverlight, having been officially announced in 2005 by John Grossman in a blog post about Avalon (the codename for WPF). This pattern based on MVC and MVP which attempts to more clearly separate the development of UI from that of the business logic and behavior in an application.
MVVM最初由Microsoft定义为与Windows Presentation Foundation(WPF)和Silverlight结合使用,并于2005年由John Grossman在有关Avalon(WPF的代号)的博客文章中正式宣布。 这种基于MVC和MVP的模式试图将UI的开发与应用程序中业务逻辑和行为的开发区分开来。

It has three main components as follows.
它具有以下三个主要组成部分。
Model — the Model used in MVVM is similar to the model used in MVC, consisting of the basic data required to run the software.
模型-MVVM中使用的模型类似于MVC中使用的模型,其中包含运行软件所需的基本数据。
View — the View is a graphical interface between the user and the design pattern, similar to the one in MVC. It displays the output of the data processed.
视图-视图是用户和设计模式之间的图形界面,类似于MVC中的界面。 它显示已处理数据的输出。
View-Model — the View-Model is on one side an abstraction of the View and, on the other, provides a wrapper of the Model data to be linked. That is, it comprises a Model that is converted to a View, and it also contains commands that the View can use to influence the Model.
视图模型-视图模型一方面是视图的抽象,另一方面则提供了要链接的模型数据的包装。 即,它包含一个转换为视图的模型,并且还包含视图可用于影响模型的命令。

MVC vs MVP vs MVVM (MVC vs MVP vs MVVM)
Let’s find out MVC Vs MVP Vs MVVM, main points of differences.
让我们找出MVC与MVP与MVVM的区别。

Performance Evaluation — When we are testing the UI performance, MVP turns out to be the one with the highest reliability and lowest hindrance when it comes to rendering frames. Data binding in MVVM creates an additional overload that could drastically affect its performance when performing complex tasks.
性能评估—当我们测试UI性能时,MVP是渲染帧时可靠性最高,障碍最小的一种。 MVVM中的数据绑定会产生额外的过载,这可能在执行复杂任务时严重影响其性能。
Compatibility — When testing the patterns based on their compatibility, MVVM was the best of the lot due to its data binding which had a positive impact. MVP fared better than MVC, which had serious restating issues.
兼容性-在基于模式的兼容性测试模式时,MVVM是其中最好的,因为其数据绑定具有积极的影响。 MVP的表现要好于MVC,后者存在严重的重述问题。
Modifiability — When we talk about design patterns, it is evident that it should be modifiable since that gives us the option of adding new features and strategies into our app.
可修改性-当我们谈论设计模式时,很明显它应该是可修改的,因为它使我们可以选择在我们的应用程序中添加新功能和策略。
- Based on these factors, we observed that changes are very less in MVP and MVVM, with MVVM contributing a lot towards maintainability. 基于这些因素,我们观察到MVP和MVVM的变化很小,而MVVM对可维护性的贡献很大。
- MVC tends to increase the number of changes in the majority of the cases. 在大多数情况下,MVC都会增加更改的数量。
Entry Point — For MVC, the entry point to the application is the Controller whereas, for MVP and MVVM, the entry point is the View.
入口点—对于MVC,应用程序的入口点是控制器,而对于MVP和MVVM,入口点是视图。
通过各种架构实施示例 (Implement the example by various architectures)
You can implement the BookSearch application to understand by using one of three architecture as the following diagram.
您可以通过使用以下三种架构之一来实现BookSearch应用程序的理解。

Easy, right? Can you implement it yourself?
容易吧? 你能自己实现吗?
翻译自: https://levelup.gitconnected.com/mvc-vs-mvp-vs-mvvm-35e0d4b933b4
mvc mvvm mvp