Question

Currently, I'm implementing MVVM pattern for a WPF application but not 100% no code behind, sometimes I put some business logic code into GUI and so what are potential problems for this? Thanks

Était-ce utile?

La solution

The whole point of MVVM is to abstract as much logic as possible away from the View, the surface that the user sees. If you're using CodeBehind to implement business logic, you're probably not practicing MVVM.

This has several benefits:

  1. It makes the code more testable. UI is difficult to test, especially UI that has CodeBehind.
  2. If the business logic is somewhere else besides the UI, you can swap out the UI for another UI (such as a mobile device or web page), and the business logic will still work.

Of course, if this is a very small application and you never intend to talk to a database on a server (a rarity these days), you may not need all this ceremony; CodeBehind might be perfectly adequate.

Licencié sous: CC-BY-SA avec attribution
scroll top