应用架构MVC、MVVM等 [英] Application Architechture MVC,MVVM etc

查看:16
本文介绍了应用架构MVC、MVVM等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MVCMVVMMVP 等架构模式仅用于表示层?
我们可以在业务逻辑层或数据访问层使用吗?
我之前认为Presentation TierView;
业务逻辑层Controller/ViewmodelData Access LayerModel.
请有人澄清这一点..

Architecture patterns like MVC,MVVM, MVP are only used in presentation tier?.
Can we use in Business Logic layer or Data access layer?
I previously thought that Presentation Tier is View;
BusinessLogic Tier is Controller/Viewmodel and Data Access Layer is Model.
please someone clarify this..

推荐答案

在架构上,我会说 MVCMVPMVVM 是表示层.每个组件之间的观点是:

Architecturally, I would say that MVC, MVP and MVVM is the presentation tier. The point of view between each components are:

  1. 查看

这个很清楚,它属于表现层.不讨论这个

This is very clear that it belongs to presentation layer. Not discussion about this

控制器/演示/视图模型

Controller / Presentation / View Model

如果去掉 N 层主体,这就是业务层.似乎这种设计模式是在没有与 N 层耦合的情况下发明的.

If you take off the N-Tier principal, this is the business tier. Seems like this design pattern were invented without taking any coupling with the N-Tier.

Controller 具有 Session 和 HttpContext 利用率.它依赖于网络.根据 N 层负责人的说法,BLL 必须不知道任何 UI.因此它适用于表示层.

Controller has Session and HttpContext utilization. It is web dependent. According to N-Tier principal, the BLL must not know any UI. Therefore it goes for presentation tier.

Presentation 具有事件/事件处理程序/委托和一些特定于 UI 的数据.(CMIIW,我对 MVP 不太熟悉).因此它适用于表示层.

Presentation has events / event handlers / delegations and some UI-specific data. (CMIIW, I'm not too fluent with MVP). Therefore it goes for presentation tier.

正如其他人所说,ViewModel 很难被归类为表示层.但是,我发现放入表示层更好.根据我使用 WPF 的经验,有时我需要使用 MVVM 特定对象,如 ObservableCollectionINotifyPropertyChangedICommand 来强制数据绑定刷新.有时需要 ViewModel 访问自定义会话状态,例如登录等.其他时候,您需要指定一些特定于 UI 的参数,例如字体颜色等.这可以通过在 View 中处理逻辑,但我发现在 ViewModel 中更容易.

As other said, ViewModel is rather hard to be classified as presentation tier. However, I find it better to put into presentation tier. In my experience using WPF, sometimes I need to use MVVM specific objects like ObservableCollection and INotifyPropertyChanged and ICommand to force data binding refresh. Sometimes it is needed for the ViewModel to access custom session state, such as login, etc. Other times, you need to specify some UI-specific parameter such as font color, etc. This may be avoided by handling the logic in View, however I find it is easier to do it in ViewModel.

另一件需要考虑的事情,使用 MVVM 会阻止我使用服务 - 存储库模式.

Another thing to consider, using MVVM prevent me to use Service - Repository pattern.

模型

如果你从 MV- 模式中去掉 N 层,这就是实体模型.它在 Asp.Net MVC 中有描述,模型将在视图中用作数据容器.但是,如果考虑到 N 层,那么这就是业务层,您对数据进行插入/更新/删除操作,以及它的逻辑所在.

If you take the N-Tier off from MV- pattern, this is the entity model. It is described at Asp.Net MVC, where the model will be used in the view, as the container for data. However, if you take N-Tier into account, then this is the business tier, where you do insert/update/delete operation to the data, and the logic for it resides.

这篇关于应用架构MVC、MVVM等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆