<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JAPF &#187; testability</title>
	<atom:link href="http://www.japf.fr/tag/testability/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.japf.fr</link>
	<description>Jeremy Alles Presentation Foundation: WPF, .Net and modern software development</description>
	<lastBuildDate>Thu, 29 Jul 2010 07:29:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Why should I use Model-View-ViewModel pattern</title>
		<link>http://www.japf.fr/2008/12/why-should-i-use-model-view-viewmodel-pattern/</link>
		<comments>http://www.japf.fr/2008/12/why-should-i-use-model-view-viewmodel-pattern/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 13:47:23 +0000</pubDate>
		<dc:creator>Jeremy</dc:creator>
				<category><![CDATA[WPF]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[model-view-viewmodel]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[testability]]></category>

		<guid isPermaLink="false">http://www.japf.fr/?p=90</guid>
		<description><![CDATA[Recently, while discussing a WPF issue on a forum, I discovered that some people didn&#8217;t know anything about the Model-View-ViewModel pattern. I&#8217;m not an expert of MVVM as I discovered it a couple of months ago. I started to use it on my first real project at work, which involve a pretty big application using [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, while discussing a WPF issue on a forum, I discovered that some people didn&#8217;t know anything about the Model-View-ViewModel pattern. I&#8217;m not an expert of MVVM as I discovered it a couple of months ago. I started to use it on my first real project at work, which involve a pretty big application using advanced TreeView, Ribbon, on-demand graphic creation, a C++ kernel, datagrid, etc. The MVVM pattern helps me to keep my design as clean as possible. In this post, I&#8217;d like to give you some of the aspects of the MVVM pattern, and useful links across the web.</p>
<p>If you find yourself:</p>
<ul>
<li>having huge .xaml.cs code behind file</li>
<li>using event handler (such as Click&#8230;) everywhere</li>
<li>tweaking TreeViewItem (using ItemContainerGenerator for example) to manipulate a TreeView</li>
<li>having tons of IValueConverter</li>
<li>… then MVVM might come to the rescue :p</li>
</ul>
<p><strong>What MVVM can offer?</strong></p>
<ul>
<li>a clean and well defined separation between the Model and the View</li>
<li>the possibility to easily leverage the power of WPF: databinding, commands, validation, and more</li>
<li>a code that is testable</li>
<li>an organization that facilitate the workflow between designers and developers</li>
<li>minimalist code-behind file (which leads to testable code)</li>
<li>facilitate the deployment of an application in multiple environment (WPF / Silverlight)</li>
</ul>
<p><strong>How is that possible?</strong></p>
<p>Here is a part of the introduction of John Gossman:</p>
<p><em>“In simple examples, the View is data bound directly to the Model. For example, a boolean in the Model can be data bound to a CheckBox, or a string field to a TextBox. In practice however, only a small subset of application UI can be data bound directly to the Model, especially if the Model is a pre-existing class or data schema over which the application developer has no control.<br />
The Model is very likely to have a data types that cannot be mapped directly to controls.  Finally we need a place to put view state such as selection or modes.<br />
The ViewModel is responsible for these tasks.  In this latter role the ViewModel contains data-transformers that convert Model types into View types, and it contains Commands the View can use to interact with the Model.”</em></p>
<p><img class="alignnone size-full wp-image-92" title="viewmodel" src="http://www.japf.fr/wp-content/uploads/2008/12/viewmodel.png" alt="viewmodel" width="468" height="164" /></p>
<ul>
<li>The View has the associated ViewModel set as its DataContext so that the View can easily data bind to ViewModel properties</li>
<li>The ViewModel reflects its changes to the Model by calling appropriate methods on the Model</li>
<li>The ViewModel exposes ICommand that the View data bind to, in order to execute actions</li>
<li>The Model signals its changes to the ViewModel by raising events</li>
</ul>
<p><strong>What are good resources to start working with MVVM?</strong></p>
<ul>
<li>Karl Shifflett started a series about MVVM, you can find his work <a href="http://karlshifflett.wordpress.com/mvvm/">here</a>.</li>
<li>Karl and Josh Smith wrote a very nice application that uses MVVM pattern. Moreover the application contains also information about internalization support. Check out the CodeProject article <a href="http://karlshifflett.wordpress.com/mvvm/internationalized-wizard-in-wpf-using-m-v-vm/">here</a>.</li>
<li>Karl wrote <a href="http://karlshifflett.wordpress.com/mvvm/input-validation-ui-exceptions-model-validation-errors/">an article</a> about a very important concept: user input validation. This is the first article of his new MVVM series.</li>
<li>WPF architect, John Gossman wrote a series of blog post about MVVM on his blog. An introduction to MVVM is <a href="http://blogs.msdn.com/johngossman/archive/2005/10/08/478683.aspx">available</a> and a good point to start.</li>
<li>Josh Smith wrote an excellent tool, Crack.Net which is built using MVVM. Crack.Net is hosted on <a href="http://www.codeplex.com/cracknetproject">CodePlex</a>, and studying the source code is a very good manner to understand how stuff fits together in the MVVM world.</li>
<li>Josh Smith wrote <a href="http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx">an article</a> about applying MVVM concepts to the WPF treeview. If you must work with a complex treeview, then you MUST read this article.</li>
<li>Marlon Grech wrote <a href="http://marlongrech.wordpress.com/2008/11/22/icollectionview-explained/">an article</a> about ICollectionView. ICollectionView is a useful interface that can be used in ViewModel classes to keep track user selection</li>
</ul>
<p>If you never heard about MVVM, or never take the time to look at it, I suggest you to take a look at some of those links. Trust me, the investisment worth it !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.japf.fr/2008/12/why-should-i-use-model-view-viewmodel-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
