Following is excrept from this article on MVVM. Can someone provide example of how these other patterns (command, DI) are used in WPF? Are there any other desgin patterns that are used in WPF that you don't see listed here ?
There are other patterns you should be aware of to assist you in MVVM. Patterns like commanding (baked into WPF, solutions for SL), mediator and gasp dependency injection. .
MVVM (Model-View-ViewModel)It is based on the Model-view-controller pattern (MVC), and is targeted at modern UI development platforms (WPF and Silverlight) in which there is a UX developer who has different requirements than a more "traditional" developer.
MVVM is the lingua franca of WPF developers because it is well suited to the WPF platform, and WPF was designed to make it easy to build applications using the MVVM pattern (amongst others).
The adapter pattern (or sometimes known as a wrapper) is one of the most useful and most popular design patterns in software engineering.
I've written the article about some of them: WPF and Silverlight design patterns
Here is a brief description of the patterns:
1) MVVM - used as a model converter and as a replacement of the code-behind. Improves testability, it is much easier to write unit tests for ViewModel.
2) Dependency Injection - used for improving testability of a class (you can write unit tests for a specific class separately from others) and for the possibility to change implementation in easier way (change a logger, cache provider, web service etc)
3) Command - can be applied to Button and MenuItem controls by default, disables controls if an action can't be executed. Also used in MVVM pattern as a replacement of code-behind events.
Other patterns from the classic book which are already used in WPF:
Data binding (between View and ViewModel) uses the Observer pattern. Also: the Factory pattern can be used to instantiate the ViewModel but that is optional.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With