<?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>Dev @ Work &#187; Patterns</title>
	<atom:link href="http://www.devatwork.nl/category/patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devatwork.nl</link>
	<description>A day in the life of a developer</description>
	<lastBuildDate>Tue, 18 Oct 2011 16:32:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Asynchronous Payment Provider Implementation Pattern</title>
		<link>http://www.devatwork.nl/2009/03/asynchronous-payment-provider-implementation-pattern/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=asynchronous-payment-provider-implementation-pattern</link>
		<comments>http://www.devatwork.nl/2009/03/asynchronous-payment-provider-implementation-pattern/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 19:27:13 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[Liones]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=435</guid>
		<description><![CDATA[Today at Liones I started working on the integration of a payment service provider (PSP) for a web shop implementation. While I was thinking about the architecture I discovered that it is actually very straightforward and that most of the application flow is reusable in different implementations with other PSPs. Take a look at the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.devatwork.nl/wp-content/uploads/2009/03/payment400x300.jpg" rel="lightbox[435]"><img class="size-full wp-image-437 alignleft" title="Payment" src="http://www.devatwork.nl/wp-content/uploads/2009/03/payment400x300.jpg" alt="Payment" width="192" height="144" /></a>Today at <a title="Liones, het Internetbureau voor Uitgevers" href="http://www.liones.nl">Liones</a> I started working on the integration of a payment service provider (PSP) for a web shop implementation. While I was thinking about the architecture I discovered that it is actually very straightforward and that most of the application flow is reusable in different implementations with other PSPs.</p>
<p>Take a look at the UML diagram below; you will notice that there are actually two flows:</p>
<ul>
<li>One synchronous, which guides the user trough the payment screen</li>
<li>One asynchronous, which notifies when the payment state changed (payment is confirmed or canceled)</li>
</ul>
<p><span id="more-435"></span><a href="http://www.devatwork.nl/wp-content/uploads/2009/03/payment-flow.png" rel="lightbox[435]"><img class="size-full wp-image-443 alignright" title="Payment Flow" src="http://www.devatwork.nl/wp-content/uploads/2009/03/payment-flow.png" alt="Payment Flow" width="250" height="337" /></a></p>
<p><strong>Synchronous flow</strong></p>
<p>A said: the synchronous flow guides the user through the confirmation, payment and thank you steps. The following steps are taken:</p>
<ol>
<li>A record is created to track the status of the payment for the order that is being made.</li>
<li>The user is redirected to the payment provider page, this can be done using various methods including HTTP GET and HTTP POST. One of the parameters is the ID of the payment record. The other parameters depend on the PSP and might include a message signature, a merchant ID or a redirect URL for example.</li>
<li>The user fills in his credit card information, IDEAL information or any other payment information supported by the PSP. Once the user has filled in that info, the PSP processes the payment and redirects the user back to the web shop application, usually with some confirmation information, like: status (failed, in processes) and a transaction ID, in the parameters.</li>
<li>The web application stores the transaction ID in the payment record and shows the thank you text to the user.</li>
</ol>
<p>That is it for the synchronous flow.</p>
<p><strong>Asynchronous flow</strong></p>
<p>The asynchronous flow, often called notification flow, is used to give the web shop status updates about the payments. This asynchronous flow is needed because a payment might take several days or even weeks to complete. For instance: when a user pays by transferring money into a designated bank account he/she usually has two weeks to do so. The asynchronous flow can be initiated by either the PSP or the web shop depending on the specific PSP implementation.</p>
<p>The single purpose of the asynchronous flow is to update the payment identified by either the payment ID (generated by the web shop) or the transaction ID (generated by the PSP). Once a payment status has been updated the asynchronous flow could send a mail to the user to inform him/her that the payment is complete.</p>
<p><strong>Conclusion</strong></p>
<p>Although the implementation specifics vary between PSP, the general flow as described above is pretty consistent for PSPs. I hope you can integrate a PSP with your web shop in the same way, if not please let me now: this pattern needs a revision.</p>

	Tags: <a href="http://www.devatwork.nl/tag/architecture/" title="architecture" rel="tag">architecture</a>, <a href="http://www.devatwork.nl/tag/liones/" title="Liones" rel="tag">Liones</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2009/03/asynchronous-payment-provider-implementation-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Model View ViewModel ( M-V-VM )</title>
		<link>http://www.devatwork.nl/2009/02/model-view-viewmodel-m-v-vm/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=model-view-viewmodel-m-v-vm</link>
		<comments>http://www.devatwork.nl/2009/02/model-view-viewmodel-m-v-vm/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 11:09:26 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[M-V-VM]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=193</guid>
		<description><![CDATA[Recently I have been working on a Windows Presentation Foundation (WPF) application designed to manage tasks. It is not the first time I developed an application in WPF. However, I was struggling with the same problem I was struggling with before: The problem: Coupling my views (WPF) to my domain model (C#). The solution I [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have been working on a Windows Presentation Foundation (WPF) application designed to manage tasks. It is not the first time I developed an application in WPF. However, I was struggling with the same problem I was struggling with before:</p>
<p><strong>The problem: Coupling my views (WPF) to my domain model (C#).</strong></p>
<p>The solution I came up with back then is to make the domain model aware of the need to bind and implement specific functionality like [<a title="System.ComponentModel.INotifyPropertyChanged" href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx">System.ComponentModel.INotifyPropertyChanged</a>]. By doing this I cluttered my domain model with non domain model code, which made the model difficult to understand and maintain, basically: No Go!</p>
<p><strong>The solution: Model-View-ViewModel pattern</strong></p>
<p>I went out looking for pattern that could help me to eliminate this code cluttering. After doing some research using my favorite search engine I discovered that there was a pattern for this problem: Model &#8211; View &#8211; ViewModel (MVVM or M-V-VM).<br />
<span id="more-193"></span></p>
<p>This pattern basically says: just wrap your domain model in another model, the view model, and implement view specific logic (like: INotifyPropertyChanged) on that view model.</p>
<p>I also implemented my commands on this view model class, I could have factored it out to view controllers but I didn&#8217;t see the need for that right now.</p>
<p>For the implementation of the commands I choose the solutions suggested by [<a title="Karl on WPF" href="http://karlshifflett.wordpress.com">Karl on WPF</a>] and [<a title="Josh Smith on WPF" href="http://joshsmithonwpf.wordpress.com/">Josh Smith</a>]: the RelayCommand class. The purpose of this class is to drastically reduce the number of command needed by providing a single class which takes a delegate to execute the actual command. It also contains some logic to hook into the WPF command infrastructure.</p>
<p>Here is my implementation of the RelayCommand in C#:</p>
<pre class="brush: csharp; title: ; notranslate">public class RelayCommand: ICommand
{
	private readonly Predicate&lt;object&gt; canExecuteMethod;
	private readonly Action&lt;/object&gt;&lt;object&gt; executeMethod;
	public RelayCommand(Action&lt;/object&gt;&lt;object&gt; executeMethod): this(executeMethod, null) {}

	public RelayCommand(Action&lt;/object&gt;&lt;object&gt; executeMethod, Predicate&lt;/object&gt;&lt;object&gt; canExecuteMethod)
	{
		// validate argument
		if (executeMethod == null)
			throw new ArgumentNullException(&quot;executeMethod&quot;);

		// set values
		this.executeMethod = executeMethod;
		this.canExecuteMethod = canExecuteMethod;
	}
	#region ICommand Members
	///&lt;summary&gt;
	///Occurs when changes occur that affect whether or not the command can execute.
	///&lt;/summary&gt;
	public event EventHandler CanExecuteChanged
	{
		add
		{
			if (canExecuteMethod != null)
				CommandManager.RequerySuggested += value;
		}
		remove
		{
			if (canExecuteMethod != null)
				CommandManager.RequerySuggested -= value;
		}
	}
	/// &lt;summary&gt;
	/// Defines the method to be called when the command is invoked.
	/// &lt;/summary&gt;
	/// &lt;param name=&quot;parameter&quot;&gt;Data used by the command.  If the command does not require data to be passed, this object can be set to null.&lt;/param&gt;
	public void Execute(object parameter)
	{
		executeMethod(parameter);
	}
	/// &lt;summary&gt;
	/// Defines the method that determines whether the command can execute in its current state.
	/// &lt;/summary&gt;
	/// &lt;returns&gt;
	/// true if this command can be executed; otherwise, false.
	/// &lt;/returns&gt;
	/// &lt;param name=&quot;parameter&quot;&gt;Data used by the command.  If the command does not require data to be passed, this object can be set to null.&lt;/param&gt;
	public bool CanExecute(object parameter)
	{
		return canExecuteMethod == null ? true : canExecuteMethod(parameter);
	}
	#endregion
	public void RaiseCanExecuteChanged(EventArgs e)
	{
		CommandManager.InvalidateRequerySuggested();
	}
}

public class RelayCommand&lt;t&gt;: ICommand
{
	private readonly Predicate&lt;/t&gt;&lt;t&gt; canExecuteMethod;
	private readonly Action&lt;/t&gt;&lt;t&gt; executeMethod;
	public RelayCommand(Action&lt;/t&gt;&lt;t&gt; executeMethod): this(executeMethod, null) {}

	public RelayCommand(Action&lt;/t&gt;&lt;t&gt; executeMethod, Predicate&lt;/t&gt;&lt;t&gt; canExecuteMethod)
	{
		// validate argument
		if (executeMethod == null)
			throw new ArgumentNullException(&quot;executeMethod&quot;);

		// set values
		this.executeMethod = executeMethod;
		this.canExecuteMethod = canExecuteMethod;
	}
	#region ICommand Members
	///&lt;summary&gt;
	///Occurs when changes occur that affect whether or not the command can execute.
	///&lt;/summary&gt;
	public event EventHandler CanExecuteChanged
	{
		add
		{
			if (canExecuteMethod != null)
				CommandManager.RequerySuggested += value;
		}
		remove
		{
			if (canExecuteMethod != null)
				CommandManager.RequerySuggested -= value;
		}
	}

	/// &lt;summary&gt;
	/// Defines the method to be called when the command is invoked.
	/// &lt;/summary&gt;
	/// &lt;param name=&quot;parameter&quot;&gt;Data used by the command.  If the command does not require data to be passed, this object can be set to null.&lt;/param&gt;
	public void Execute(object parameter)
	{
		executeMethod((T)parameter);
	}
	/// &lt;summary&gt;
	/// Defines the method that determines whether the command can execute in its current state.
	/// &lt;/summary&gt;
	/// &lt;returns&gt;
	/// true if this command can be executed; otherwise, false.
	/// &lt;/returns&gt;
	/// &lt;param name=&quot;parameter&quot;&gt;Data used by the command.  If the command does not require data to be passed, this object can be set to null.&lt;/param&gt;
	public bool CanExecute(object parameter)
	{
		return canExecuteMethod == null ? true : canExecuteMethod((T)parameter);
	}
	#endregion
	public void RaiseCanExecuteChanged(EventArgs e)
	{
		CommandManager.InvalidateRequerySuggested();
	}
}</pre>
<p><strong>Conclusion</strong></p>
<p>The MVVM pattern is a great pattern which allows you to separate the WPF view from your domain model, preventing code cluttering. I recommend every WPF or Silverlight developer to look into this pattern and use it when you encounter the same problem I had.</p>
<p><strong>References:</strong></p>
<p><a title="Karl on WPF" href="http://karlshifflett.wordpress.com/mvvm/">http://karlshifflett.wordpress.com/mvvm/</a></p>
<p><a title="Josh Smith on WPF" href="http://joshsmithonwpf.wordpress.com/category/mvvm/">http://joshsmithonwpf.wordpress.com/category/mvvm/</a></t></object></p>

	Tags: <a href="http://www.devatwork.nl/tag/m-v-vm/" title="M-V-VM" rel="tag">M-V-VM</a>, <a href="http://www.devatwork.nl/tag/wpf/" title="WPF" rel="tag">WPF</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2009/02/model-view-viewmodel-m-v-vm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doing the Laundry</title>
		<link>http://www.devatwork.nl/2008/07/doing-the-laundry/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=doing-the-laundry</link>
		<comments>http://www.devatwork.nl/2008/07/doing-the-laundry/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 14:12:22 +0000</pubDate>
		<dc:creator>Bert Willems</dc:creator>
				<category><![CDATA[Patterns]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=116</guid>
		<description><![CDATA[Yesterday I decided that it was time to buy my own washing machine, finally. It works like a charm , some of you might think that it something trivial to do but for me it was a huge challenge . Anyway, since my friends are here I wont be rude by writing a long post, [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I decided that it was time to buy my own washing machine, finally. It works like a charm <img src='http://www.devatwork.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  , some of you might think that it something trivial to do but for me it was a huge challenge <img src='http://www.devatwork.nl/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  . Anyway, since my friends are here I wont be rude by writing a long post, see you!</p>
No tag for this post.]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2008/07/doing-the-laundry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test-Driven Design en het Just Say Thanks Patroon</title>
		<link>http://www.devatwork.nl/2007/03/test-driven-design-en-het-just-say-thanks-patroon/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=test-driven-design-en-het-just-say-thanks-patroon</link>
		<comments>http://www.devatwork.nl/2007/03/test-driven-design-en-het-just-say-thanks-patroon/#comments</comments>
		<pubDate>Mon, 26 Mar 2007 17:28:16 +0000</pubDate>
		<dc:creator>Bert Willems</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[Test-Driven Development]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/index.php/2007/03/26/test-driven-design-en-het-just-say-thanks-patroon/</guid>
		<description><![CDATA[In deze post zal ik een vergelijking maken tussen TDD (Test-Driven Development) en het &#8220;Just Say Thanks&#8221; Patroon. Test-Driven Development is een werkmethode dat toegepast wordt in de software ontwikkeling. Test-Driven Development [1] werkt als volgt: Elke iteratie begint met het schrijven van een geautomatiseerde test, vaak unit test genoemd. De ontwikkelaar schrijft deze test [...]]]></description>
			<content:encoded><![CDATA[<p>In deze post zal ik een vergelijking maken tussen TDD (Test-Driven Development) en het &#8220;Just Say Thanks&#8221; Patroon. Test-Driven Development is een werkmethode dat toegepast wordt in de software ontwikkeling.<span id="more-5"></span></p>
<p>Test-Driven Development [<a href="#1">1</a>] werkt als volgt:<br />
Elke iteratie begint met het schrijven van een geautomatiseerde test, vaak unit test genoemd. De ontwikkelaar schrijft deze test op basis van de specificaties en eisen van de te ontwikkelen functionaliteit. De test controleert dus of de geschreven implementatie van de functionaliteit correct is. Vervolgens voert de ontwikkelaar de test uit om deze te laten falen, aangegeven door een rood licht, omdat er nog geen implementatie code is geschreven.</p>
<p>Nu de ontwikkelaar weet dat de test goed functioneert kan hij beginnen met de eigenlijke implementatie van de functionaliteit. Waarneer de implementatie voltooid is kan de ontwikkelaar de geschreven code testen door de test weer uit te voeren, en deze keer, mits de implementatie goed geschreven is, zal de test slagen en een groen licht geven. De ontwikkelaar kan nu met zekerheid zeggen dat de code werkt volgens de specificaties en eisen. Voor een uitgebreidere en correctere uitleg: Bron [<a href="#1">1</a>].</p>
<p>Het &#8220;Just Say Thanks&#8221; patroon [<a href="#2">2</a>] gaat over het oprecht bedanken van mensen voor hun inspanning hoe onbetekenend die ook mag lijken. Iedereen vind het immers leuk om gerespecteerd te worden. Dit patroon heb ik leren kennen over een boek dat gaat over veranderingen en ideeën binnen een bedrijf: &#8220;Fearless Change&#8221; [<a href="#3">3</a>] van Mary Lynn Manns en Linda Rising.</p>
<p>Test-Driven Development maakt eigenlijk gebruik van het &#8220;Just Say Thanks&#8221; patroon, en wel om de volgende reden: Eerst schrijf je een geautomatiseerde test, vervolgens voer je die test uit. De test zal niet slagen, en een rood licht geven, omdat er nog geen implementatie code geschreven is. Vervolgens schrijf je de implementatie code en voer je de test nogmaals uit. Deze keer zal, indien de implementatie goed geschreven is, de test slagen en krijg je een groen licht te zien. Dat groene licht is een metafoor voor iemand die tegen je zegt:</p>
<p><strong><em>Je hebt goed werk afgeleverd. Oftewel het &#8220;Just Say Thanks&#8221; patroon.</em></strong></p>
<p>Als laatste wil ik opmerken dat het Just Say Thanks patroon in het dagelijkse leven veel vaker gebruikt zou moeten worden. Het kost niks om iemand even te bedanken, maar het zal die andere persoon een goed gevoel geven en dat weer naar jou reflecteren. Toegegeven, ik pas het patroon ook lang niet altijd toe, maar verscheidende keren dat ik het gebruikt heb kreeg ik een positieve reactie! Ik kan het iedereen aanraden om het te proberen.</p>
<p>Bedankt voor de aandacht,<br />
Bert Willems</p>
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td valign="top">[<a name="1"></a>1]</td>
<td valign="top"><a title="Test-Driven Development" href="http://en.wikipedia.org/wiki/Test_driven_development">Test-Driven Development &#8211; Wikipedia</a></td>
</tr>
<tr>
<td valign="top">[<a name="2"></a>2]</td>
<td valign="top">Just Say Thanks Patroon<br />
Maakt deel uit van het boek &#8220;Fearless Change&#8221; [<a href="#3">3</a>].</td>
</tr>
<tr>
<td valign="top">[<a name="3"></a>3]</td>
<td valign="top">Fearless Change<br />
Patterns for Introducing New Ideas<br />
May Lynn Manns en Linda Rising<br />
0-201-74157-1</td>
</tr>
</table>

	Tags: <a href="http://www.devatwork.nl/tag/books/" title="Books" rel="tag">Books</a>, <a href="http://www.devatwork.nl/tag/patterns/" title="Patterns" rel="tag">Patterns</a>, <a href="http://www.devatwork.nl/tag/test-driven-development/" title="Test-Driven Development" rel="tag">Test-Driven Development</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2007/03/test-driven-design-en-het-just-say-thanks-patroon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

