Dan Crevier's Blog

In search of a better name...

DataModel-View-ViewModel pattern series

Published Wednesday, October 11, 2006 7:00 PM by dancre
Filed under:

Comments

 

Andrew Stopford's Weblog said:

Dan Crevier has series of posts on the DM-V-VM pattern, including how to implement it and how ot test

October 12, 2006 7:13 AM
 

Bryant Likes said:

Thanks! Now you just need a DM-V-VM tag so that all your posts come up in one place. :)

October 12, 2006 12:18 PM
 

Houman said:

Thanks this was great.  

I specially liked the way you injected control into the StockModel [StockModel(symbol, IStockQuoteProvider)]

To be honest, I had some difficulty grasbing the why & how of the ActivateModel.  I had to really think about it, but I think I get it now...with that said, would you please give an example of why you needed to do reference counting?  In other words: For which scenarios the ActiviateModel you described isn't good enough?

Thanks again.

Houman

October 27, 2006 1:32 PM
 

Life, Universe and Everything according to Dirk said:

I may have included one of those in one of my link roundups, but this is a topic very dear to my heart

October 30, 2006 5:40 AM
 

dancre said:

One example scenario where I needed ref counting in the activation was in Max when we had nested views where the inner view's template was chosen programmatically based on the model state. Both the outer view and inner view needed to activate the model. If you don't need this, no need to add the complexity.

October 30, 2006 11:05 PM
 

Suhas Sane said:

Thanks for a post, it is very good. Currently I am working on creating a back end accounting application with WPF. Since we anticipate many calls to service layer (WCF), I liked the concept of DataModel. It was curious that the constructor of the viewModel \ DataModel is doing actual data extraction. I would have thought you will have separate GetData Method. Usually I try to perform minimal task in constructors.

I am also struggling about how to write an automated unit test for the PortfolioViewModel equivalent. To test the behavior of AddCommandModel and RemoveCommandModel etc. Any information you can provide in that domain can be helpful.

October 31, 2006 9:25 AM
 

dancre said:

Actually the data extraction really happens when the model is activated.

To unit test AddCommandModel/RemoveCommandModel, you can set up some test data in PortfolioViewModel. Then, you can get the commands through the PropertyViewModel accessors and call OnQueryEnabled and OnExecute with different parameters to try it out. In cases where you need to get to private methods and data, use PrivateObject or PrivateType.

October 31, 2006 11:21 AM
 

Suhas Sane said:

I tried to use your suggestion to call OnQueryEnabled  and OnExecute  directly. I keep getting error "The type CanExecuteRoutedEventArgs has no constructors defined".  I am not able to find any sample which directly instantiates this class.

My aim is to create a console application to test the behavior of presenter. I guess if I create a windows based application I can use command binding and test this via Command object. But not sure how to do this in Console app.

November 13, 2006 12:07 PM
 

dancre said:

You can use Visual Studio's PrivateObject helper class to help out:

Type[] types = { typeof(ICommand), typeof(object) };

object[] param = { myRoutedCommand, null };

PrivateObject privateCanExecuteArgs = new PrivateObject(typeof(CanExecuteRoutedEventArgs), types, param);

CanExecuteRoutedEventArgs canExecuteArgs = (CanExecuteRoutedEventArgs)privateCanExecuteArgs.Target;

You can do this from a command line app.

November 13, 2006 12:27 PM
 

Mike Brown said:

Regarding multiple parameters for the CommandModel: what if we set the ViewModel as the parameter for the CommandModel. This way the CommandModel can be the link between the ViewModel and the DataModel and can validate against N number of values.

December 18, 2006 3:35 PM
 

dancre said:

Yes, that would definitely work. If you do things through an interface, it will keep the command from being specific to one view model.

December 19, 2006 12:38 AM
 

IRhetoric - Karsten Januszewski said:

I've been meaning to document how I wrapped the Twitter API ... in 4.5 seconds. There is a very powerful

June 8, 2007 9:31 PM
 

外部部落格 said:

I've been meaning to document how I wrapped the Twitter API ... in 4.5 seconds. There is a very powerful

July 20, 2007 5:16 AM
 

Community Blogs said:

Introduction I've been posting a lot about Silverlight lately, but hey, here is a WPF post, and about

April 11, 2008 4:55 PM
 

Ryan Cromwell said:

Tonight I presented for the Dayton .Net Developers Group on WPF. Unlike my previous Lap Around WPF @

April 23, 2008 11:30 PM
 

Julian Dominguez said:

In this post (of what may become a series of posts if I find some interest from the community) I compare

April 30, 2008 1:37 AM
 

.NET & Funky Fresh said:

First I'd like to say that I'm stoked about the work the Prism team has been doing.  I have

June 6, 2008 9:24 AM
 

Obiwan Jacobi said:

This post is based on an interpretation of a pattern called View-View Model-Document or View-View Model

June 29, 2008 8:09 AM
 

Elise's blog said:

Après avoir participé à quelques projets WPF depuis maintenant un peu plus d'un an, je suis dans une

August 6, 2008 9:39 AM
 

Elise's blog said:

Après avoir participé à quelques projets WPF depuis maintenant un peu plus d'un an, je suis dans une

August 12, 2008 7:06 AM
 

Tre Simpla said:

Checking out DataModel ViewModel patterns.

September 16, 2008 6:29 PM
 

Christopher Bennage said:

Table of Contents Since my last post on building ChumChase, I've had a couple of projects that have

November 7, 2008 10:06 PM
 

Community Blogs said:

Table of Contents Since my last post on building ChumChase, I've had a couple of projects that have

November 7, 2008 10:59 PM
 

Christopher Bennage said:

Table of Contents Since my last post on building ChumChase, I've had a couple of projects that have

November 10, 2008 8:58 AM
 

ReBitting said:

Serie Tutorial Pattern DM-V-VM

December 15, 2008 9:02 AM
 

Павел Ивченков said:

Вторая часть из серии постов, в которых мы последовательно пройдем все этапы соз

February 6, 2009 2:13 AM
 

Community Blogs said:

In this article I will explain how to implement MVVM pattern in Silverlight. I was very overjoyed when

February 15, 2009 12:32 PM
 

#.think.in said:

#.think.in infoDose #21 (10th Mar - 15th Mar)

March 16, 2009 1:11 AM
 

nasa said:

都是Silverlight做的游戏

http://www.silverarcade.com/Games

April 28, 2009 4:37 AM
New Comments to this post are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker