What is purpose of EmployeesDetailsPresentationModel?

Topics: Prism v2 - WPF 3.5, Prism v2 - WPF 4, Prism v4 - WPF 4
Jun 29, 2010 at 4:06 PM

First off, is the View Injection QuickStart following the Supervising Presenter or Presentation Model Separated Presenation Pattern, or a mixture of the two? It seems to me if there is an EmployeesDetailsPresenationModel, then there should be an EmployeesListPresentationModel and EmployeesPresentationmodel as well.

To me, the EmployeesDetailsPresenationModel seems unnecessary, why not just move its logic into the EmployeesDetailsPresenter? I am fairly new to Composite WPF and am having a hard time understanding this. Thanks in advance.

Jul 2, 2010 at 2:28 PM

anyone?

 

Jul 13, 2010 at 10:40 PM
Edited Jul 13, 2010 at 10:47 PM

Hi,

Good question, based on the Separated Patterns in the Prism documentation this quickstart uses MVP with “Presenter First Composition” since the presenter is created first and then hooked up to a suitable view and a model.

Additionally, Supervising Pattern as well as Presentation Model are variants of the MVP. This quickstart uses Supervising Pattern, since views are updated by presenters, and views interact with presentation models/models. Also this quickstart is mentioned in the Supervising Pattern under the section Example as sample.

Regarding to whether EmployeesPresentationModel and EmployeesListPresentationModel should exist, for an "orthodox way" the answer is yes, tough they are not strictly needed. The presentation models are needed when you want to bind a view to a non-existent property in the model. In this cases, a presentation model exposes those properties in a bind-able way without changing the model itself. For example, the EmployeesDetailsPresentationModel wrap the model to expose the AddressMapURL, which does not exist on the Employee model. For more information about data binding:

It is possible to move the EmployeeDetailsPresentationModel logic to the presenter. But this would imply that the presenter has to set the AddressMapURL to the view (through the view interface). In addition, if you need the view to be updated every time the AddressMapURL changes, the presenter would need to observe the model. On the other hand, with the presentation model approach you are taken advantage of bindings to avoid this extra work. 

Note: the Presentation Model pattern unifies the presentation logic and bind-able content in only one class (usually called ViewModel). This pattern is also known as Model-View-ViewModel, which is used in the new Prism v4.

Back to Supervising Pattern, ideally all the bind-able content like properties (e.g. AddressMapURL) live in a presentation model or in a model. While all the complex interaction between view –> model and model –> view in a presenter. The following examples are some of common interactions considered complex:

  1. Change the color of a control.
  2. Hide/Show controls dynamically.
  3. Listen a click button or menu item.

However, Prism provides guidance, so you could choice either to follow the patterns as they are proposed or make your own implementation.

I hope you can find it useful.

Fernando Antivero
http://blogs.southworks.net/fantivero

Jul 14, 2010 at 2:34 AM

Thank you for the clarification.