问题描述
架构模式,如 MVC
, MVVM
, MVP
仅在presentation层使用?
我们能否在业务逻辑层和数据访问层使用?
我previously认为 presentation层code>是
查看
;
BusinessLogic层
是控制器/视图模型
和数据访问层
是模式
。
请人澄清这..
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..
推荐答案
在架构上,我要说的是 MVC
, MVP
和 MVVM
是presentation层。各组件之间的观点是:
Architecturally, I would say that MVC
, MVP
and MVVM
is the presentation tier. The point of view between each components are:
-
查看
View
这是很清楚的,它属于presentation层。这个不讨论
This is very clear that it belongs to presentation layer. Not discussion about this
控制器/ presentation /视图模型
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.
控制器
具有会话和HttpContext的利用率。这是网络依赖。根据N层校长,BLL一定不知道任何UI。因此,它也适用于presentation层。
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层。
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.
由于对方表示,视图模型
是相当困难被列为presentation层。不过,我觉得它更好地投入presentation层。根据我的经验使用WPF,有时我需要使用MVVM特定对象,如的ObservableCollection
和 INotifyPropertyChanged的
和的ICommand
来强制数据绑定刷新。有时需要使用视图模型
来访问自定义会话状态,如登录等其他时候,你需要指定一些特定的用户界面参数,如字体颜色等这可能通过处理视图逻辑是可以避免的,但是,我发现这是比较容易做,在视图模型。
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 prevent我使用服务 - 库模式
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等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!