Refactor CAB Smart Part Quick Start Project to “Presentation Model”

May 15th, 2006

Composite UI Application Block (CAB) is really a powerful framework for smart client applications. It comes with samples implementing the Model View Control (MVC) pattern and the Model View Presenter (MVP) pattern. There is actually a third pattern called Presentation Model. See the pictures from http://jgoodies.com/articles/patterns-and-binding.pdf.

MVC MVP PM

As described in Martin Fowler’s article (MVP, PM), the presenter in MVP has no state and the views need to provide interface allow presenter to manipulate them. The Presentation Model holds and synchronizes the state, but no need to create view interfaces.

Choice between MVP and PM, as per Martin Fowler’s article:

This decision would be strongly influenced by a decent framework that supports such synchronization. If you have such a thing then Presentation Model seems the better choice.

Compare to MVC or MVP, I prefer using the Presentation Model, because it has a centralized place to store state/data and centralized event source to notify views to update themselves. The CAB’s Event Broker is perfect for notification. So I modified the Smart Part Quick Start Project to become the ”Presentation Model” pattern.  Here is the Source code.

What have I done?

  1. Refactor to extract interface ICustomerListView and ICustomerDetailView from the views*. 
  2. Added CustomerPresentationModel class that implements the above two interfaces. 
  3. Define the CustomerPresentationModel class as Service. **
  4. Inject the CustomerPresentationModel instances into views using service dependency injection. ***
  5. Published events CustomerSelected events CustomerCommentsSelected from the CustomerPresentationModel class.
  6. Subscribed the above events in BrowseCustomerWorkItem and ViewCustomerWorkItem

* Extract interface from the views sound very much similar to MVP, isn’t it? The difference is that in MVP, the presenter uses the interfaces to push data into the views, means that presenter refers to views. In PM, the controller implements the interface. The views pull data from the controller, means that views refer to controller. The “refer to” is a very good case of using depedency injection.

**

[Service]
public class CustomerPresentationModel: ICustomerDetailView, ICustomerListView
{
}

***
public partial class CustomerListView : TitledSmartPart
{
    private ICustomerListView controller = null;

    [ServiceDependency(Required = true, Type = typeof(CustomerPresentationModel))]
    public ICustomerListView Controller
    {
        set { controller = value; }
    }
    ….
}

Tags:

Entry Filed under: Programming

1 Comment Add your own

  • 1. Yiyi Sun - Programming Bl&hellip  |  August 11th, 2006 at 7:57 pm

    [...] In my previous post, I refactored CAB Smart Part Quick Start project to use Presentation Model. This time I refactored the project to use Model View Presenter. Note: the Presenter class is borrowed from Smart Client Software Factory, SC-SF. [...]

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

March 2010
M T W T F S S
« Feb    
1234567
891011121314
15161718192021
22232425262728
293031  

Most Recent Posts


1