揭开MVC,MVP,MVVM,VIPER这几种模式的神秘面纱

三种架构模式——MVC、MVP、MVVM MV系列框架中,M和V分别指Model层和View层,但其功能会因为框架的不同而变化。Model层是数据模型,用来存储数据;View层是视图,展示Model层的数据。虽然在不同的框架中,Model层和View层的内容可能会有所差别,但是其基础功能不变,变的只是数据的传输方式 。本文讲解MVC、MVP和MVVM三种架构模式。 阅读详情

iOS Architecture Patterns

Demystifying MVC, MVP, MVVM and VIPER

Feeling weird while doing MVC in iOS? Have doubts about switching to MVVM? Heard about VIPER, but not sure if it worth it?
Keep reading, and you will find answers to questions above, if you don’t — feel free to complain in comments.
You are about to structure your knowledge about architectural patterns in iOS environment. We’ll briefly review some popular ones and compare them in theory and practice going over a few tiny examples. Follow links if you need more details about any particular one.

Mastering design patterns might be addictive, so beware: you might end up asking yourself more questions now than before reading this article, like these:

Who supposed to own networking request: a Model or a Controller?

How do I pass a Model into a View Model of a new View?

Who creates a new VIPER module: Router or Presenter?

这里写图片描述

Why care about choosing the architecture?

Because if you don’t, one day, debugging a huge class with dozens different things, you’ll find yourself being unable to find and fix any bugs in your class.”. Naturally, it is hard to keep this class in mind as whole entity, thus, you’ll always be missing some important details. If you are already in this situation with your application, it is very likely that:

  • This class is the UIViewController subclass.
  • Your data stored directly in the UIViewController
  • Your UIViews do almost nothing
  • The Model is a dumb data structure
  • Your Unit Tests cover nothing

And this can happen, even despite the fact that you are following Apple’s guidelines and implementing Apple’s MVC pattern, so don’t feel bad. There is something wrong with the Apple’s MVC, but we’ll get back to it later.

Let’s define features of a good architecture:

  1. Balanced distribution of responsibilities among entities with
    strict roles.
  2. Testability usually comes from the first feature (and don’t worry: it is easy with appropriate architecture).
  3. Ease of use and a low maintenance cost.

Why Distribution?

Distribution keeps a fair load on our brain while we trying to figure out how things work. If you think the more you develop the better your brain will adapt to understanding complexity, then you are right. But this ability doesn’t scale linearly and reaches the cap very quickly. So the easiest way to defeat complexity is to divide responsibilities among multiple entities following the single responsibility principle.

Why Testability?

This is usually not a question for those who already felt gratitude to unit tests, which failed after adding new features or due to refactoring some intricacies of the class. This means the tests saved those developers from finding issues in runtime, which might happen when an app is on a user’s device and the fix takes a week to reach the user.

Why Ease of use?

This does not require an answer but it is worth mentioning that the best code is the code that has never been written. Therefore the less code you have, the less bugs you have. This means that desire to write less code should never be explained solely by laziness of a developer, and you should not favour a smarter solution closing your eyes to its maintenance cost.

MV(X) essentials

Nowadays we have many options when it comes to architecture design patterns:

  • MVC
  • MVP
  • MVVM
  • VIPER

First three of them assume putting the entities of the app into one of 3 categories:

  • Models — responsible for the domain data or a data access layer which
    manipulates the data, think of ‘Person’ or ‘PersonDataProvider’
    classes.
  • Views — responsible for the presentation layer (GUI), for iOS
    environment think of everything starting with ‘UI’ prefix.
  • Controller/Presenter/ViewModel — the glue or the mediator between the
    Model and the View, in general responsible for altering the Model by
    reacting to the user’s actions performed on the View and updating the
    View with changes from the Model.

*Having entities divided allows us to:*

  • understand them better (as we already know)
  • reuse them (mostly applicable to the View and the Model)
  • test them independently

Let’s start with MV(X) patterns and get back to VIPER later.

MVC

How it used to be

Before discussing Apple’s vision of MVC let’s have a look on the traditional one.
Traditional MVC

In this case, the View is stateless. It is simply rendered by the Controller once the Model is changed. Think of the web page completely reloaded once you press on the link to navigate somewhere else. Although it is possible to implement the traditional MVC in iOS application, it doesn’t make much sense due to the architectural problem — all three entities are tightly coupled, each entity knows about the other two. This dramatically reduces reusability of each of them — that is not what you want to have in your application. For this reason, we skip even trying to write a canonical MVC example.
Traditional MVC doesn’t seems to be applicable to modern iOS development.

Apple’s MVC

Expectation
Cocoa MVC

The Controller is a mediator between the View and the Model so that they don’t know about each other. The least reusable is the Controller and this is usually fine for us, since we must have a place for all that tricky business logic that doesn’t fit into the Model.
In theory, it looks very straightforward, but you feel that something is wrong, right? You even heard people unabbreviating MVC as the Massive View Controller. Moreover, view controller offloading became an important topic for the iOS developers. Why does this happen if Apple just took the traditional MVC and improved it a bit?

Apple’s MVC

Reality
Realistic Cocoa MVC

Cocoa MVC encourages you to write Massive View Controllers, because they are so involved in View’s life cycle that it’s hard to say they are separate. Although you still have ability to offload some of the business logic and data transformation to the Model, you don’t have much choice when it comes to offloading work to the View, at most of times all the responsibility of the View is to send actions to the Controller. The view controller ends up being a delegate and a data source of everything, and is usually responsible for dispatching and cancelling the network requests and… you name it.

How many times have you seen code like this:

The cell, which is the View configured directly with the Model, so MVC guidelines are violated, but this happens all the time, and usually people don’t feel it is wrong. If you strictly follow the MVC, then you supposed to configure the cell from the controller, and don’t pass the Model into the View, and this will increase the size of your Controller even more.

Cocoa MVC is reasonably unabbreviated as the Massive View Controller.

The problem might not be evident until it comes to the Unit Testing (hopefully, it does in your project). Since your view controller is tightly coupled with the view, it becomes difficult to test because you have to be very creative in mocking views and their life cycle, while writing the view controller’s code in such a way, that your business logic is separated as much as possible from the view layout code.

Let’s have a look on the simple playground example:

MVC example

MVC assembling can be performed in the presenting view controller
This doesn’t seem very testable, right? We can move generation of greeting into the new GreetingModel class and test it separately, but we can’t test any presentation logic (although there is not much of such logic in the example above) inside the GreetingViewController without calling the UIView related methods directly (viewDidLoad, didTapButton) which might cause loading all views, and this is bad for the unit testing.
In fact, loading and testing UIViews on one simulator (e.g. iPhone 4S) doesn’t guarantee that it would work fine on the other devices (e.g. iPad), so I’d recommend to remove “Host Application” from your Unit Test target configuration and run your tests without your application running on simulator.
The interactions between the View and the Controller aren’t really testable with Unit Tests
With all that said, it might seems that Cocoa MVC is a pretty bad pattern to choose. But let’s assess it in terms of features defined in the beginning of the article:

  • Distribution — the View and the Model in fact separated, but the View
    and the Controller are tightly coupled.
  • Testability — due to the bad distribution you’ll probably only test
    your Model.
  • Ease of use — the least amount of code among others patterns. In
    addition everyone is familiar with it, thus, it’s easily maintained
    even by the unexperienced developers.

Cocoa MVC is the pattern of your choice if you are not ready to invest more time in your architecture, and you feel that something with higher maintenance cost is an overkill for your tiny pet project.
Cocoa MVC is the best architectural pattern in terms of the speed of the development.

MVP

Cocoa MVC’s promises delivered
Passive View variant of MVP

Doesn’t it look exactly like the Apple’s MVC? Yes, it does, and it’s name is MVP (Passive View variant). But wait a minute… Does this mean that Apple’s MVC is in fact a MVP? No, its not, because if you recall, there, the View is tightly coupled with the Controller, while the MVP’s mediator, Presenter, has nothing to do with the life cycle of the view controller, and the View can be mocked easily, so there is no layout code in the Presenter at all, but it is responsible for updating the View with data and state.

What if I told you, the UIViewController is the View.

In terms of the MVP, the UIViewController subclasses are in fact the Views and not the Presenters. This distinction provides superb testability, which comes at cost of the development speed, because you have to make manual data and event binding, as you can see from the example:

MVP example

Important note regarding assembly

The MVP is the first pattern that reveals the assembly problem which happens due to having three actually separate layers. Since we don’t want the View to know about the Model, it is not right to perform assembly in presenting view controller (which is the View), thus we have to do it somewhere else. For example, we can make the app-wide Router service which will be responsible for performing assembly and the View-to-View presentation. This issue arises and has to be addressed not only in the MVP but also in all the following patterns.
Let’s look on the features of the MVP:

  • Distribution — we have the most of responsibilities divided between
    the Presenter and the Model, with the pretty dumb View (in the
    example above the Model is dumb as well).
  • Testability — is excellent, we can test most of the business logic
    due to the dumb View.
  • Easy of use — in our unrealistically simple example, the amount of
    code is doubled compared to the MVC, but at the same time, idea of
    the MVP is very clear.

    MVP in iOS means superb testability and a lot of code.

MVP

With Bindings and Hooters

There is the other flavour of the MVP — the Supervising Controller MVP. This variant includes direct binding of the View and the Model while the Presenter (The Supervising Controller) still handles actions from the View and is capable of changing the View.

Supervising Presenter variant of the MVP

But as we have already learned before, vague responsibility separation is bad, as well as tight coupling of the View and the Model. That is similar to how things work in Cocoa desktop development.
Same as with the traditional MVC, I don’t see a point in writing an example for the flawed architecture.

MVVM

The latest and the greatest of the MV(X) kind
The MVVM is the newest of MV(X) kind thus, let’s hope it emerged taking into account problems MV(X) was facing previously.
In theory the Model-View-ViewModel looks very good. The View and the Model are already familiar to us, but also the Mediator, represented as the View Model.

MVVM

It is pretty similar to the MVP:

  • the MVVM treats the view controller as the View
  • There is no tight coupling between the View and the Model

In addition, it does binding like the Supervising version of the MVP; however, this time not between the View and the Model, but between the View and the View Model.
So what is the View Model in the iOS reality? It is basically UIKit independent representation of your View and its state. The View Model invokes changes in the Model and updates itself with the updated Model, and since we have a binding between the View and the View Model, the first is updated accordingly.

Bindings

I briefly mentioned them in the MVP part, but let’s discuss them a bit here. Bindings come out of box for the OS X development, but we don’t have them in the iOS toolbox. Of course we have the KVO and notifications, but they aren’t as convenient as bindings.
So, provided we don’t want to write them ourselves, we have two options:

  • One of the KVO based binding libraries like the RZDataBinding or the
    SwiftBond
  • The full scale functional reactive programming beasts like
    ReactiveCocoa, RxSwift or PromiseKit.

In fact, nowadays, if you hear “MVVM” — you think ReactiveCocoa, and vice versa. Although it is possible to build the MVVM with the simple bindings, ReactiveCocoa (or siblings) will allow you to get most of the MVVM.
There is one bitter truth about reactive frameworks: the great power comes with the great responsibility. It’s really easy to mess up things when you go reactive. In other words, if do something wrong, you might spend a lot of time debugging the app, so just take a look at this call stack.

Reactive Debugging

In our simple example, the FRF framework or even the KVO is an overkill, instead we’ll explicitly ask the View Model to update using showGreeting method and use the simple property for greetingDidChange callback function.

MVVM example

And again back to our feature assessment:

  • Distribution — it is not clear in our tiny example, but, in fact, the
    MVVM’s View has more responsibilities than the MVP’s View. Because
    the first one updates it’s state from the View Model by setting up
    bindings, when the second one just forwards all events to the
    Presenter and doesn’t update itself.
  • Testability — the View Model knows nothing about the View, this allows us to test it easily. The View might be also tested, but since it is UIKit dependant you might want to skip it.
  • Easy of use — its has the same amount of code as the MVP in our example, but in the real app where you’d have to forward all events from the View to the Presenter and to update the View manually, MVVM would be much skinnier if you used bindings.

    The MVVM is very attractive, since it combines benefits of the aforementioned approaches, and, in addition, it doesn’t require extra code for the View updates due to the bindings on the View side. Nevertheless, testability is still on a good level.

VIPER

LEGO building experience transferred into the iOS app design

VIPER is our last candidate, which is particularly interesting because it doesn’t come from the MV(X) category.

VIPER

  • Interactor — contains business logic related to the data (Entities) or networking, like creating new instances of entities or fetching them from the server. For those purposes you’ll use some Services and Managers which are not considered as a part of VIPER module but rather an external dependency.
  • Presenter — contains the UI related (but UIKit independent) business logic, invokes methods on the Interactor.
  • Entities — your plain data objects, not the data access layer, because that is a responsibility of the Interactor.
  • Router — responsible for the segues between the VIPER modules.

    Basically, VIPER module can be a one screen or the whole user story of your application — think of authentication, which can be one screen or several related ones. How small are your “LEGO” blocks supposed to be? — It’s up to you.

  • Model (data interaction) logic shifted into the Interactor with the Entities as dumb data structures.

  • Only the UI representation duties of the Controller/Presenter/ViewModel moved into the Presenter, but not the data altering capabilities.
  • VIPER is the first pattern which explicitly addresses navigation responsibility, which is supposed to be resolved by the Router.

    Proper way of doing routing is a challenge for the iOS applications, the MV(X) patterns simply don’t address this issue.

The example doesn’t cover routing or interaction between modules, as those topics are not covered by the MV(X) patterns at all.

Yet again, back to the features:

  • Distribution — undoubtedly, VIPER is a champion in distribution of responsibilities.
  • Testability —no surprises here, better distribution — better testability.
  • Easy of use — finally, two above come in cost of maintainability as you already guessed. You have to write huge amount of interface for classes with very small responsibilities.

So what about LEGO?

While using VIPER, you might feel like building The Empire State Building from LEGO blocks, and that is a signal that you have a problem. Maybe, it’s too early to adopt VIPER for your application and you should consider something simpler. Some people ignore this and continue shooting out of cannon into sparrows. I assume they believe that their apps will benefit from VIPER at least in the future, even if now the maintenance cost is unreasonably high. If you believe the same, then I’d recommend you to try Generamba — a tool for generating VIPER skeletons. Although for me personally it feels like using an automated targeting system for cannon instead of simply taking a sling shot.

Conclusion

We went though several architectural patterns, and I hope you have found some answers to what bothered you, but I have no doubt that you realised that there is no silver bullet so choosing architecture pattern is a matter of weighting tradeoffs in your particular situation.
Therefore, it is natural to have a mix of architectures in same app. For example: you’ve started with MVC, then you realised that one particular screen became too hard to maintain efficiently with the MVC and switched to the MVVM, but only for this particular screen. There is no need to refactor other screens for which the MVC actually does work fine, because both of architectures are easily compatible.

从零开始学习信号完整性(SIPI)--1 简介 信号完整性就是研究如何让驱动芯片发出的信号经过传输通道被接收芯片正确接收的学问。 信号完整性包含了三个要素: 信号:是被传输的主体,我们首先要了解、熟悉信号的特性。 芯片:分为驱动芯片和接收芯片,信号完整性工程师就是要实现信号在驱动芯片和接收芯片之间的正确传输。 传输通道:是传输信号的介质,是信号所走的“路”。如何实现信号的正确传输呢?那就要信号完整性工程师为信号“修路”、“搭桥”。 阅读详情

相关推荐

FoundationPose 4090部署 真实场景迁移

复现并应用foundationpose

m0_52835296的博客 613

MVC、MVP、MVVM三种区别及适用场合

MVC模式最初生根于服务器端的Web开发,后来渐渐能够胜任客户端Web开发,能够满足其复杂性和丰富性。 MVC:是Model-View-Controller的缩写,它将应用程序划分为三个部分: 1.视图(View):用户界面,只负责渲染HTML2.控制器(Controller):业务逻辑,负责调度model和view3.模型(Model):数据保存,只负责存储数据,请求数据,更新数据 MVC...

棠樾的博客 3980

GNSS差分码偏差(DCB)从原理到实战:如何避免数据处理中的常见错误

本文深入解析GNSS差分码偏差(DCB)的原理及其对高精度定位的关键影响。针对数据处理中因忽略DCB校正导致的常见错误,如单系统PPP高程偏差、多系统融合精度下降及电离层研究失真等,提供了实战解决方案与主流DCB产品获取、集成方法,帮助用户有效规避陷阱,提升数据处理精度。

k5l6m的博客 223

MVC、MVP、MVVM

MVC 中的 Controller 只知道 Model 的接⼝,因此它没有办法控制 View 层的更新,MVP 模式中,View 层的接⼝暴露给了 Presenter 因此可以在 Presenter 中将 Model 的变化和 View 的变化绑定在⼀起,以此来实现 View 和 Model 的同步 更新。因此当Model中的数据改变时会 触发View层的刷新,View中由于⽤户交互操作⽽改变的数据也会在Model中 同步。模型与视图完全分离。创建数据,并提供访问、修改数据的接口,执行修改数据之后的操作。

Camellia_77的博客 1237

学习笔记( 11 ) - 解决:finalshell连接虚拟机(ubuntu)超时,主机ping不通虚拟机,主机没有VMnet8网卡, Connection refused: connect

解决:finalshell连接虚拟机(ubuntu)超时,主机ping不通虚拟机,主机没有VMnet8网卡, Connection refused: connect

烟溪彭于晏的博客 2万+

SAP财务凭证实战:如何用Coding Block快速添加客户化字段(附ABAP代码)

本文详细介绍了在SAP财务凭证中利用Coding Block技术快速添加客户化字段的完整流程,包括技术架构解析、实战配置步骤(OBC4/OB41)及ABAP增强开发。通过案例演示如何高效扩展字段(如增长曲线类型),实现全流程集成且无需修改数据表,显著提升财务凭证的灵活性和可追溯性。

weixin_29271263的博客 225

1.Vue概念

文章目录前端开发发展历程前端开发框架变迁MVCMVPMVVM实例相关资料 前端开发发展历程 原生js(浏览器兼容性差) Jquery等(浏览器兼容性好,频繁操作dom) 前端模板引擎(省去频繁dom操作。处理数据死板,数量大时效率低) Angular.js、vue.js(不用频繁操作dom,数据处理灵活) 前端开发框架变迁 MVC MVC模式最初生根于服务器端的Web开发,后来渐渐能够胜任客户端Web开发,能够满足其复杂性和丰富性。 MVC是Model-View-Controller的缩写,它将应用程

高新园养鸡场 652

Miniconda3迁移(附图详细过程)

服务器上目录占满,想要将conda迁移到其他目录下的操作方法,详细教程。

2301_77554343的博客 6942

[译]iOS架构模式——解密MVC、MVP、MVVM和VIPER

为避免撕逼,提前声明:本文纯属翻译,仅仅是为了学习,加上水平有限,见谅! 【原文】https://medium.com/ios-os-x-development/ios-architecture-patterns-ecba4c38de52 使用MVC进行iOS开发感觉到很怪异?在切换到MVVM的时候心存疑虑?听说过VIPER,但是不知道是否值得采用? 读下去,这篇文章将为你一一解惑。 如果你正打算...

weixin_34032827的博客 200

OCS2 入门教程(一)

OCS2 是专为切换系统优化控制(ptimalontrol forwitchedystems,OCS2)定制的 C++ 工具箱。该工具箱提供以下算法的高效实现:SLQ:连续时间域约束 DDPiLQR:离散时域约束 DDPSQP:基于 HPIPM 的多重打靶算法IPM: 基于非线性内点法的多重搜索算法SLP:基于 PIPG 的顺序线性规划算法OCS2 通过增强拉格朗日法(Augmented Lagrangian)或松弛障碍法(relaxed barrier methods)处理一般路径约束。

机器人控制与仿真应用 7836

fast-lio系列改进版本

2.回环检测的优化结果,更新到FAST-LIO2的当前帧位姿中,幷进行ikdtree的重构,进而更新submap。其它的效果还不清楚,实测lio部分稳定性很好。用fast-lio_slam就很稳定。融合了fast-lio2和sc-pgo,两部分分开运行,SC-PGO从FAST-LIO2节点获取里程计和激光雷达点云主题。的作者kim在FAST-LIO2的基础上,添加SC-PGO模块,通过加入ScanContext全局描述子,进行回环修正,SC-PGO模块与FAST-LIO2解耦,非常方便,很优秀的工作。

z1872385的博客 3189

[译]iOS Architecture Patterns(iOS架构模式)

原文地址 #揭开MVC,MVP,MVVM和VIPER的神秘面纱 Translator-CL Don’t miss the iOS Developer Roadmap for 2018! 在iOS中用MVC时感觉怎么样? 有关切换到MVVM的疑问? 听说VIPER,但不确定它是否值得? 您即将在iOS环境中构建有关架构模式的知识。 我们将简要回顾一些流行的,并在理论和实践上对它们进行比较,仅举几个...

weixin_34306446的博客 244

实战篇| app爬虫不用真机

之前写过一篇基于真机app爬虫《App爬虫实战篇-以华为真机手机爬取集换社的app为例》,如果大家有用真机爬虫的经历,会深刻认识到真的不方便,一是自己的手机,经常会被电话、微信等打断,二是闲置手机,面对小批量数据还能勉强,大批量爬虫,会导致成本指数级上升,并且控制起来相对麻烦。以下就是常见的模拟器。emulator -avd my_avd -no-snapshot-save # 启动时不保存 snapshot。emulator -avd my_avd -wipe-data # 清除数据(恢复到出厂)

youbingchen的博客 596

fir.im Weekly - iOS/Android 应用程序架构解析

假如问你一个iOS or Android app的架构,你会从哪些方面来说呢?本期 fir.im Weekly 收集了关于 iOS/Android 开发资源,也加入了一些关于 Web 前端方面的分享。希望能帮你拓宽技术栈,带来一些新的思考。iOS开发学习路线图@Cocochina 论坛里 hldsjk 总结了自己的 iOS 开发学习路线图,非常强大。在线预览地址:http://ios.skyfox

FIRim的专栏 1599

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

android app 技术架构分析,fir.im Weekly - iOS/Android 应用程序架构解析

假如问你一个iOS or Android app的架构,你会从哪些方面来说呢?本期 fir.im Weekly 收集了关于 iOS/Android 开发资源,也加入了一些关于 Web 前端方面的分享。希望能帮你拓宽技术栈,带来一些新的思考。iOS开发学习路线图@Cocochina 论坛里 hldsjk 总结了自己的 iOS 开发学习路线图,非常强大。在线预览地址:http://ios.skyfo...

weixin_42404983的博客 358

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

iOS中资源分享

唐巧的博客 objc中国--为中国 Objective-C 社区带来最佳实践和先进技术,原英文objc.io在此 NSHipster(英文)中文版的在此 mattt-thompson在NSHipster的专栏 王巍的博客 喵神维护的swift技巧网站,每周三更新 sunny的博客 ibireme的博客--YYKit作者 里脊串的开发随笔 叶孤城_(码界吴彦祖)的简书 晓月的专栏

刺骨寒的博客 791

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

MVC、MVP、MVVM模式的概念与区别

首先MVC,MVP,MVVM都是为了解决UI页面与逻辑代码分离而出现的模式,MVP和MVVM都是MVC的基础上演化而来。他不属于某种语言的框架,只要是有UI页面与逻辑代码我们都可以使用这几种框架去搭建我们的项目。他是一种框架模式。M和V分别指Model层和View层,但其功能会因为框架的不同而变化。Model层是数据模型,用来存储数据;View层是视图,展示Model层的数据。虽然在不同的MV(XX)框架中,Model层和View层的内容可能会有所差别,但是其基础功能不变,变的只是 数据的传输方式。

小孟来码的博客 8524

一、什么是 mvvm? MVC、MVP、MVVM三种模式的区别与详解

MVC、MVP、MVVM都是常见的软件架构模式。MVC(Model-View-Controller)架构模式中,将应用程序分为三个主要部分:模型(Model)、视图(View)和控制器(Controller)。Controller负责处理用户交互和调度业务逻辑,View负责显示数据,Model负责数据的存储和逻辑处理。MVP(Model-View-Presenter)架构模式,类似于MVC,但将View和Model的交互逻辑抽象到了Presenter中。

qq_44849312的博客 1万+

MVC、MVP与MVVM

1.MVC模式 MVC是应用最广泛的软件架构之一,一般MVC分为:Model(模型),View(视图),Controller(控制器)。 这主要是基于分层的目的,让彼此的职责分开.View一般用过Controller来和Model进行联系。Controller是Model和View的协调者,View和Model不直接联系。基本都是单向联系。 M - Model :提供数据,用于封装与应用程序的业务逻辑相关的数据以及对数据的处理方法。 V - View : 用户界面,是应用程序中处理数据显示的部分。通常视图是

小权权的博客 839

MVC,MVP,MVVM是什么?

文章目录前言一、MVC是什么?二、MVP是什么?三、MVVM是什么?总结 前言 MVC,MVP,MVVP它们本质上是就是三种逐渐迭代的分离界面和业务逻辑的设计模式。其迭代过程由MVC->MVP->MVVM 提示:以下是本篇文章正文内容,下面案例可供参考 一、MVC是什么? MVC是Model-View-Controller简称,它首次把系统分成Model,View和Controller这三部分,明确的把用户界面和业务逻辑分离开来。 M(Model):这里的Model就是业务逻辑的抽象

Dr_chaser的博客 1411

一篇文章讲清楚Android中的MVC、MVP、MVVM架构 (附实现代码)

MVC、MVP、MVVM大体上都是把系统划分成3个模块:视图层、业务层、数据层。但是他们的通信方式、数据流动方向不一致,形成了不同的架构。其后面产生的架构都是为了更好的解耦,解决已有架构的不足。每个架构都有自己的优缺点,没有最好的架构,只有最合适的架构。

bugyinyin的博客 6785

MVVM、MVC、MVP 的区别

MVC:适用于传统的Web应用,尤其是服务器端渲染的应用。它通过控制器协调模型和视图之间的交互。 MVP:适用于需要高度测试性的应用,特别是移动应用。它通过Presenter来分离视图和业务逻辑。 MVVM:适用于现代的单页应用(SPA),特别是使用JavaScript框架如Vue、Angular或React构建的应用。它通过数据绑定简化了视图和模型之间的同步。

小赵的博客 4181

MVVM、MVP、MVC

MVVM、MVP、MVC的三大核心部分、核心机制、工作流程以及优势

2201_75883040的博客 1483
上一篇: 图片拉伸
Mainning
博客等级 码龄12年 7粉丝 16原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值