winform实现mvvm
Software architectures are powerful weapons for developers.
软件体系结构是开发人员的强大武器。
In iOS development, before SwiftUI came along, Cocoa MVC was the most suitable software architecture in most cases. (If you want to know about Cocoa MVC, refer my another article)
在iOS开发中,在SwiftUI出现之前,可可MVC在大多数情况下是最合适的软件架构。 (如果您想了解可可MVC,请参阅我的另一篇文章 )
But now, EnvironmentObject’s data binding feature in SwiftUI allows to implement MVVM architecture easily. So I think MVVM has become the standard software architecture in iOS app(in Swift UI) development.
但是现在,SwiftUI中的EnvironmentObject的数据绑定功能允许轻松实现MVVM体系结构。 因此,我认为MVVM已成为iOS应用程序(在Swift UI)开发中的标准软件体系结构。
In this article, I will describe what is MVVM and how to implement MVVM in Swift UI by creating a simple counter app.
在本文中,我将介绍什么是MVVM,以及如何通过创建一个简单的计数器应用程序在Swift UI中实现MVVM。
It’s difficult to use Software architecture in real applications just by reading.
仅通过阅读就很难在实际应用程序中使用软件体系结构。
So, let’s implement by yourself to understand MVVM by your heart ❤️
因此,让我们自己实施以真正了解MVVM❤️
什么是MVVM? (What is MVVM?)
MVVM is a software architecture invented by John Gossman in 2005.
MVVM是John Gossman在2005年发明的一种软件体系结构。
MVVM has three components Model-View-ViewModel
MVVM具有三个组件: M odel- V iew- V iew M odel
Note that View and ViewModel are connected with data binding to share ViewModel status.
请注意,View和ViewModel通过数据绑定连接以共享ViewModel状态。
模型 (Model)
Model has domain logic and its data not related to UI. Model is the same as it is in other software architectures like MVC, MVP.
模型具有域逻辑及其与UI不相关的数据。 模型与其他软件体系结构(例如MVC,MVP)相同。
For example, accessing database, control device, calculate price, etc — every logics not related to UI are included in Model
例如,访问数据库,控制设备,计算价格等-模型中包含与UI不相关的每个逻辑
It’s important that Model is completely independent of View and ViewModel, it must be able to be built alone.
完全独立于View和ViewModel的模型很重要,它必须能够单独构建。
视图 (View)
View is a component for accepting user inputs and rende