Quantcast
Channel: Overroot Blog » mvvm
Viewing all articles
Browse latest Browse all 3

Model-View-ViewModel Presenter pattern in WPF and Prism

$
0
0

If you look at 10 different sample applications of PRISM chances are that all 10 of them will have different pattern implemented. To give you the taste of confusion it can cause you, let me list down all the different terms that you’ll come across

  • MVVM
  • MVP
  • Controller
  • Presenter
  • PresentationModel
  • ViewModel
  • View
  • ViewDiscovery
  • ViewInjection
  • View first composition
  • Presenter first composition

Now don’t get bogged down in explanation of all these terms because you’ll be more confused than ever. Some times its better not to give names to concept until you understand the concept very well; then you can call it kitty, pooh or ViewInjection. Whatever helps you refer to it and remember it.

So let me try to explain things a bit…

  • Each Module can have 0 or more views
  • Modules that do not have any view usually provider services to the application
  • Each Module may have a single Controller
  • Controller is a class with a single Run method in which you typically subscribe to different composite events and inject or modify views (via presenters)
  • Each view should be in a separate folder inside the module in which there is View (user control), IView, ViewPresenter, IViewPresenter, ViewModel.
  • ViewModel is the shape of the data that you want to show on view or possibly holder of commands. In presence of IView commands are usually not required because you can implement events in IView. I like commands more though. The delegate for the DelegateCommand points to methods in the corresponding presenter.
  • Presenter is the class which is responsible for getting data from services, populating the viewmodel and attaching it to view.
  • Service is a class which abstracts out your business logic and data access.
  • Each Module has a Module file in which there is Initialize method. Thats where you register your implementations against interfaces or register views with region.
  • You only register views with region when you want that view to automatically appear when that region is shown (view discovery).
  • In rest of the places your controller either injects the view or you write some InjectionService that injects your views in some region as and when required. (view injection)
  • There is one presenter per view. Some views may not even have a presenter if they are static.

What is PresentationModel that is used in Prism examples? Its a mix of presenter and view model. You can use it if you’re short of time or if the presenter is very simple. However I believe the patterns should be consistently followed in an application instead of some modules being based on MVVM, some on MVP and some on MVVMP. In very large PRISM applications this may be unavoidable though.


Viewing all articles
Browse latest Browse all 3

Trending Articles