Spike - there is only a model and view! What's the pattern?

Aug 7, 2008 at 12:01 AM

Yesterday's spike is very impressive!  Before I continue I should note that the  _Prism/Prism.UnityContainerAdapter does not have a reference to the lib/Unity.dll (I got a compile error); I simply removed the reference to my Unity.dll (1.1.0.0) and added a reference to the libs 1.0.0.0 dll and all was happy:)

So what is the pattern when all you have is a xaml view (no code behind file) and a PresentationModel?   Looks like MVP (particularly Passive) is going to have to move aside...

Does the team have any blogs that we can subscribe to?


Views/ProjectsListView/ProjectResourceDictionary.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ViewModelComposition.Modules.Project">

    <DataTemplate DataType="{x:Type local:ProjectsListPresentationModel}">
        <StackPanel>
            <TextBlock Text="This employee is part of the following projects:"></TextBlock>
            <ListView x:Name="ProjectsList" ItemsSource="{Binding Projects}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Project" DisplayMemberBinding="{Binding Path=ProjectName}"></GridViewColumn>
                        <GridViewColumn Header="Role" DisplayMemberBinding="{Binding Path=Role}"></GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
        </StackPanel>
    </DataTemplate>
</ResourceDictionary>


Views/ProjectsListView/ProjectsListPresentationModel.cs

//===============================================================================
// Microsoft patterns & practices
// Composite WPF (PRISM)
//===============================================================================
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System.Collections.ObjectModel;
using ViewModelComposition.Modules.Project.Services;

namespace ViewModelComposition.Modules.Project
{
    public class ProjectsListPresentationModel
    {
        private IProjectService projectService;

        public ProjectsListPresentationModel(IProjectService projectService)
        {
            this.projectService = projectService;
            Projects = new ObservableCollection<BusinessEntities.Project>();
        }

        public void SetProjects(int employeeId)
        {

            var projects = this.projectService.RetrieveProjects(employeeId);
            Projects.Clear();
            foreach (var project in projects)
            {
                Projects.Add(project);
            }
        }
        public ObservableCollection<BusinessEntities.Project> Projects { get; set; }

        public string HeaderInfo
        {
            get { return "Current Projects"; }
        }
    }
}

 

Aug 7, 2008 at 12:12 PM

Hi Bill,

A colleague that works with the Prism team has been blogging about this topic, and explaining the differences between these patterns.
Check this posts:

John Gossman is also blogging about this. 

Please let me know if this helps,

Ezequiel Jadib
http://blogs.southworks.net/ejadib  

Aug 7, 2008 at 12:20 PM
By the way, the spike that Bill is talking about is the one published on 2008-10-06 called ViewModelCompositionSpike.

Ezequiel Jadib
http://blogs.southworks.net/ejadib
Aug 7, 2008 at 3:20 PM
Edited Aug 7, 2008 at 3:24 PM
@Ezequiel, Thanks!  Exactly what I was looking for.  Can P&P define the pattern?  We have Presentation Model, M-V-VM and DM-V-VM.

To further complicate matters I trust Fowler will split the Presentation Model, e.g., "Passive PM" if the view is going to handle sychronization suggesting the View will reference the Model (as it does in the spike demo).   As Fowler indicates this is more loosely coupled but doesn't permit testing sychronization.  EDITED: I think I have that backwards - if he was consistent (which I'm sure he would be) passive would be the Model handling synchronization ;)  The point being that it will probably be split...

In addition, I really think Dan Crevier's "distinction"  between a DataModel and ViewModel is important.

Guidance from P&P will prevent dis-information as occurred with MVP when it was split by Fowler in 2006;  a majority of the community (that I was learning from) was noting the difference between MVC and MVP was that in MVP the view did not communicate with the model (Passive MVP).   It wasn't until I stumbled onto Fowler's site that I realized this wasn't the case... Since then I'm pretty much sticking with Fowler and P&P for guidance.