Compare between 3-Layer pattern and MVVM

后端 未结 4 824
后悔当初
后悔当初 2021-02-04 17:20

i don\'t know MVVM. i always follow 3-layer patter where one layer is UI, another layer is Business layer and last layer is Data access layer.

in this layer we send requ

相关标签:
4条回答
  • 2021-02-04 17:33

    The Layers

    As opposed to what ppl wrote before me - the MVVM pattern is not about splitting the UI Layer into 3 layers, it's about splitting the UI Layer into two additional layers - The View and ViewModel.

    so if we had DAL, BLL, and UI, now we have Model(DAL & BLL) and ViewModel + View (instead of just one layer UI).

    it's still 3 layers but orchestrated differently (and if you really think about it - DAL was never really a layer - it's a helper class at most, so the aforementioned 3-layer was in actuality just 2 layers, that are now becoming 3 layers in MVVM).

    The Reasons

    if you think about it, you'll see that in 3 layers architecture, usually the UI is mixed with presentation code, and application logic code. this violates SRP (Single Responsibility Principle) and is bad for several reasons. in MVVM the UI Layer is separated into two layers. the ViewModel, which is in charge of the Application Logic, and the View, which is in charge solely on presentations.

    This allows you three very important things:

    1. better code Maintainability.

    2. easier to work with VS designer and Blend. aka Blendability. (this is arguably the strongest feature of MVVM. It really boosts up productivity)

    3. allows for testing of the ViewModel with automated tests, whereas up until now we had to test the UI itself, and doing automated tests on UI is complex. This is called Testability

    on a personal note; I've been writing in n-tier architecture for years. I started practising MVVM a little over a year ago. It could be a rough ride in some times, but man, it's really worth the effort.

    0 讨论(0)
  • 2021-02-04 17:43

    MVVM is arguably a three layer architecture itself. Those layers all exist within the same application.

    "3-layer" also sometimes refers to n-tier architecture, which is more about separating the UI, the service layer, and the data layer, onto separate servers. If you have that sort of layering, then MVVM will not replace it. It will only augment the UI layer, splitting it into its own three layers.

    Here's a write-up of MVVM that shows some relation between classic MVC, through MVP and MVVM:

    http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

    Also see my answer to this other question. It explains some of the reason you would use MVVM over older variations on MVC.

    0 讨论(0)
  • 2021-02-04 17:50

    MVVM is specifically relevant to WPF, Silverlight/Moonlight and Windows Phone 7 because it takes advantage of the powerful databinding that is built into these frameworks.

    0 讨论(0)
  • 2021-02-04 17:55

    MVVM is for building the UI layer. It is a pattern that enables a very nice interaction between your business objects and the UI-framework. You don't have to change your 3-Tier pattern. MVVM is on another abstraction level.
    Here you find a very good video introducing MVVM and probably answering a lot of questions.

    0 讨论(0)
提交回复
热议问题