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..
相关问题
- How to dynamically load partial view Via jquery aj
- ObservableCollection in ViewModel is not updated w
- Is it possible to send a List<Object> in MVV
- Shared common definitions across C/C++ (unmanaged)
- How to make an element reference a StaticResource
相关文章
- Forward request from servlet to jsp
- Best way to implement MVVM bindings (View <-> V
- superclass mismatch for class CommentsController (
- play2 framework my template is not seen. : package
- Using LiveData to set visibility of TextView
- app:visibleGone cannot resolve on android Databind
- Why doesn't there exists a subi opcode for MIP
- DDD Architecture - Where To Put Common Methods/Hel
The patterns you mention provide concepts to couple business and presentation tier. Considering a classical three tier architecture with the tiers you've mentioned: Data Access Layer, Business Logic, Presentation Layer, then
MVVM
,MVC
,MVP
provide concepts for the coupling of Presentation Tier and Business Logic. As the main idea is a loose coupling between the two to avoid logical dependencies between the two layers as much as possible, I would think of them as a kind of mediator (in the meaning of the word, not the pattern) or glue between them.Let me clarify this for MVVM, exemplary:
You can write a complete presentation tier in WPF without utilizing
MVVM
. Just as well you can write the business logic without knowing the concept ofMVVM
. You don't need ViewModels at all to build a working application.But: You have no chance to cleanly separate the concerns of presentation/UI and the actual logic which performs the tasks your software has been written for. The border between the two is kind of fuzzy in the real world: You calculate data, now you want to transform the data to display it in a diagram. Is this business logic? Yes and no. Is this UI logic? Yes and no. There's a grey zone: Kind of logic, kind of UI. This is where
MVVM
(and the like) kick in: You add a layer between business and presentation which is dedicated to this grey zone only.For MVVM: The View is the View, it's the presentation layer. And the ViewModel is the grey zone, which is neither real Presentation, nor real business logic, but the glue between them. The Model is the model, it's the business logic. It could even be written without knowing that it will be used in a WPF application (theoretically). And there can be business logic, which is not even a model in the MVVM meaning, because it is not UI related at all.
Below this, comes everything else with the DAL at the bottom. The DAL should really not care about how business logic and presentation are glued together and is beyond the scope of the discussed patterns.
Architecturally, I would say that
MVC
,MVP
andMVVM
is the presentation tier. The point of view between each components are:View
This is very clear that it belongs to presentation layer. Not discussion about this
Controller / Presentation / View Model
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
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
has events / event handlers / delegations and some UI-specific data. (CMIIW, I'm not too fluent with MVP). Therefore it goes for presentation tier.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 likeObservableCollection
andINotifyPropertyChanged
andICommand
to force data binding refresh. Sometimes it is needed for theViewModel
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.Another thing to consider, using MVVM prevent me to use Service - Repository pattern.
Model
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.