mvc mvvm mvp_mvc vs mvp vs mvvm

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应用程序的可视化,处理和数据管理职责分开。

Image for post
separate the responsibilities of visualizing, processing, and data management
分开可视化,处理和数据管理的职责

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进行了深入的描述,它在普及其使用方面发挥了作用。 模式将应用程序分为三个部分。

Image for post
  • 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.

    控制器-视图层和模型层由一个或多个控制器粘合在一起。

Image for post
MVC on Android
Android上的MVC

模型–视图–演示者 (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环境的模型。

Image for post

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。

Image for post
MVP on Android
Android上的MVP

模型-视图-视图模型 (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的开发与应用程序中业务逻辑和行为的开发区分开来。

Image for post

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.

    视图模型-视图模型一方面是视图的抽象,另一方面则提供了要链接的模型数据的包装。 即,它包含一个转换为视图的模型,并且还包含视图可用于影响模型的命令。

Image for post
MVVM on Android
Android上的MVVM

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的区别。

Image for post

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应用程序的理解。

Image for post
MVC vs MVP vs MVVM implementation for the BookSearch application
适用于BookSearch应用程序的MVC,MVP,MVVM实现

Easy, right? Can you implement it yourself?

容易吧? 你能自己实现吗?

翻译自: https://levelup.gitconnected.com/mvc-vs-mvp-vs-mvvm-35e0d4b933b4

mvc mvvm mvp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
旅游社交小程序功能有管理员和用户。管理员有个人中心,用户管理,每日签到管理,景点推荐管理,景点分类管理,防疫查询管理,美食推荐管理,酒店推荐管理,周边推荐管理,分享圈管理,我的收藏管理,系统管理。用户可以在微信小程序上注册登录,进行每日签到,防疫查询,可以在分享圈里面进行分享自己想要分享的内容,查看和收藏景点以及美食的推荐等操作。因而具有一定的实用性。 本站后台采用Java的SSM框架进行后台管理开发,可以在浏览器上登录进行后台数据方面的管理,MySQL作为本地数据库,微信小程序用到了微信开发者工具,充分保证系统的稳定性。系统具有界面清晰、操作简单,功能齐全的特点,使得旅游社交小程序管理工作系统化、规范化。 管理员可以管理用户信息,可以对用户信息添加修改删除。管理员可以对景点推荐信息进行添加修改删除操作。管理员可以对分享圈信息进行添加,修改,删除操作。管理员可以对美食推荐信息进行添加,修改,删除操作。管理员可以对酒店推荐信息进行添加,修改,删除操作。管理员可以对周边推荐信息进行添加,修改,删除操作。 小程序用户是需要注册才可以进行登录的,登录后在首页可以查看相关信息,并且下面导航可以点击到其他功能模块。在小程序里点击我的,会出现关于我的界面,在这里可以修改个人信息,以及可以点击其他功能模块。用户想要把一些信息分享到分享圈的时候,可以点击新增,然后输入自己想要分享的信息就可以进行分享圈的操作。用户可以在景点推荐里面进行收藏和评论等操作。用户可以在美食推荐模块搜索和查看美食推荐的相关信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值