WPF Programming Methodology

前端 未结 4 1671
予麋鹿
予麋鹿 2020-11-21 13:59

In my APP I\'m using an API of a software that my tool is managing. I\'ve DAL that contain 16 classes, 3 of them are singletons. I\'ve some logic in the .cs fil

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-21 14:26

    These are mine specific to MVVM

    1) Increases the "Blendability" of your views (ability to use Expression Blend to design views). This enables a separation of responsibilities on teams that are lucky enough to have a designer and a programmer... each can work independent of the other.

    2) "Lookless" view logic. Views are agnostic from the code that runs behind them, enabling the same view logic to be reused across multiple views or have a view easily retooled or replaced. Seperates concerns between "behavior" and "style".

    3) No duplicated code to update views. In code-behind you will see a lot of calls to "myLabel.Text = newValue" sprinkled everywhere. With MVVM you can be assured the view is updated appropriately just by setting the underlying property and all view side-effects thereof.

    4) Testability. Since your logic is completely agnostic of your view (no "myLabel.Text" references), unit testing is made easy. You can test the behavior of a ViewModel without involving its view. This also enabled test-driven development of view behavior, which is almost impossible using code-behind.

    The other two patterns are really sort of separate in terms of the concerns they address. You can use MVVM with MVP and MVC (most good samples out there do some form of this).

    In fact, MVP (w/ a Passive View, rather than a Supervising Controller) is really just a variant of MVVM, in my opinion.

提交回复
热议问题