<?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; Trilobyte</title>
	<atom:link href="http://www.devatwork.nl/author/trilobyte/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>Baking IL With DynamicMethod</title>
		<link>http://www.devatwork.nl/2009/05/baking-il-with-dynamicmethod/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=baking-il-with-dynamicmethod</link>
		<comments>http://www.devatwork.nl/2009/05/baking-il-with-dynamicmethod/#comments</comments>
		<pubDate>Sun, 31 May 2009 11:13:23 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MSIL]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=477</guid>
		<description><![CDATA[At the moment I am building a new script engine which is consists of text and expressions embedded in them. Those expressions are basically calls to functions and have any number of arguments. The implementation of those functions is done in C#. At compile time I don&#8217;t know which methods are going to be called [...]]]></description>
			<content:encoded><![CDATA[<p>At the moment I am building a new script engine which is consists of text and expressions embedded in them. Those expressions are basically calls to functions and have any number of arguments. The implementation of those functions is done in C#.</p>
<p>At compile time I don&#8217;t know which methods are going to be called so I have to invoke them at runtime. The most obvious way to do that is to use the reflection API of .NET to do a late bound method call. Although, IMHO, this is a perfectly valid solution to this problem it isn&#8217;t exactly fast.</p>
<p>System.Reflection.Emit.DynamicMethod is a better alternative for late bound method invocation when it comes to performance. Although it requires you to write Intermediate Language (IL) it is actually quite easy to use.</p>
<p><span id="more-477"></span>Let me first show you an example:</p>
<pre class="brush: csharp; title: ; notranslate">public class Program
{
public delegate void SayHello(string name);

public static void Main(string[] args)
{
var sayHelloMethod = BakeHelloMethod();
sayHelloMethod(&quot;Trilobyte&quot;);
}

public static SayHello BakeHelloMethod()
{
// get the System.Console.Write method
Type consoleType = typeof (Console);
MethodInfo writeMethodInfo = consoleType.GetMethod(&quot;Write&quot;, new[] {typeof (string)});

// create a new dynamic method with return type void and one argument of type string and get its IL generator
var dynamicMethod = new DynamicMethod(string.Empty, typeof (void), new[] {typeof (string)});
ILGenerator methodGenerator = dynamicMethod.GetILGenerator();

// first write 'Hello, '
methodGenerator.Emit(OpCodes.Ldstr, &quot;Hello, &quot;);
methodGenerator.Emit(OpCodes.Call, writeMethodInfo);

// next write the name which is the first argument
methodGenerator.Emit(OpCodes.Ldarg_0);
methodGenerator.Emit(OpCodes.Call, writeMethodInfo);

// finish the method
methodGenerator.Emit(OpCodes.Ret);

// create a delegate to the method we just created
return (SayHello)dynamicMethod.CreateDelegate(typeof (SayHello));
}
}</pre>
<p>Creating a late bound method call using DynamicMethod isn&#8217;t as complex as you might think. It only took 10 lines of code to generate a functional method. The only difficult part is baking the IL yourself, but you can use tool like <a title=".NET Reflector" href="http://www.red-gate.com/products/reflector/">Reflector</a> to decompile C# code and see how it works in IL.</p>
<p>Although I don&#8217;t use IL very often, maybe once a year, I still find it a useful tool to optimize performance of applications and I recommend to invest some time in learning the basics because it gives you a great insight in how the CLR actually works.</p>
<p>Cheers!</p>
No tag for this post.]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2009/05/baking-il-with-dynamicmethod/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two old articles</title>
		<link>http://www.devatwork.nl/2009/04/two-old-articles/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=two-old-articles</link>
		<comments>http://www.devatwork.nl/2009/04/two-old-articles/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 10:10:08 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=470</guid>
		<description><![CDATA[I just added two of my old articles about the Windows Template Library: WTL PictureBox WTL Resourceless Dialog Toolkit You can also find these articles on the CodeProject and CodeGuru. No tag for this post.]]></description>
			<content:encoded><![CDATA[<p>I just added two of my old articles about the Windows Template Library:</p>
<p><a href="http://www.devatwork.nl/index.php/articles/wtl-picture-box/">WTL PictureBox</a></p>
<p><a href="http://www.devatwork.nl/index.php/articles/wtl-resourceless-dialog-toolkit/">WTL Resourceless Dialog Toolkit</a></p>
<p>You can also find these articles on the <a href="http://www.codeproject.com">CodeProject </a>and <a href="http://www.codeguru.com">CodeGuru</a>.</p>
No tag for this post.]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2009/04/two-old-articles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Lucene.NET articles</title>
		<link>http://www.devatwork.nl/2009/03/lucenenet-articles/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lucenenet-articles</link>
		<comments>http://www.devatwork.nl/2009/03/lucenenet-articles/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 14:51:19 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[lucene]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=423</guid>
		<description><![CDATA[I just published the Lucene.NET articles I have been working on. I hope you like them. Here is an overview of the articles I have written: Introduction to Lucene Indexing basics Search basics Alternatives ( did you mean …) Faceted search / Drill down Class reference Cheers! Tags: lucene]]></description>
			<content:encoded><![CDATA[<p>I just published the Lucene.NET articles I have been working on. I hope you like them.</p>
<p>Here is an overview of the articles I have written:</p>
<ol>
<li><a href="../index.php/articles/lucenenet/introduction-to-lucenenet-lucenenet/">Introduction to Lucene</a></li>
<li><a href="../index.php/articles/lucenenet/indexing-basics-lucenenet/">Indexing basics</a></li>
<li><a href="../index.php/articles/lucenenet/search-basics-lucenenet/">Search basics</a></li>
<li><a href="../index.php/articles/lucenenet/alternatives-did-you-mean-lucenenet/">Alternatives ( did you mean …)</a></li>
<li><a href="../index.php/articles/lucenenet/faceted-search-and-drill-down-lucenenet/">Faceted search / Drill down</a></li>
<li><a href="../index.php/articles/lucenenet/class-reference-lucenenet/">Class reference</a></li>
</ol>
<p>Cheers!</p>

	Tags: <a href="http://www.devatwork.nl/tag/lucene/" title="lucene" rel="tag">lucene</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2009/03/lucenenet-articles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BitArray Calculating Cardinality</title>
		<link>http://www.devatwork.nl/2009/02/bitarray-calculating-cardinality/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bitarray-calculating-cardinality</link>
		<comments>http://www.devatwork.nl/2009/02/bitarray-calculating-cardinality/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 15:51:54 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[faceted]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=312</guid>
		<description><![CDATA[For my faceted search Lucene.NET implementation I needed to get the cardinality of a BitArray. The cardinality is the number of bits in turned on. I found a VB snippet and I converted that one to C#. Here is my implementation: The reflection access to the private field of BitArray isn&#8217;t exactly fast, but I [...]]]></description>
			<content:encoded><![CDATA[<p>For my faceted search <a title="Lucene.NET" href="http://incubator.apache.org/lucene.net/" target="_blank">Lucene.NET</a> implementation I needed to get the cardinality of a <a title="System.Collections.BitArray" href="http://msdn.microsoft.com/en-us/library/system.collections.bitarray.aspx">BitArray</a>. The cardinality is the number of bits in turned on. I found a VB snippet and I converted that one to C#.</p>
<p>Here is my implementation:</p>
<pre class="brush: csharp; title: ; notranslate">private static readonly byte[] _bitsSetArray256 = new byte[] { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 };

public static int GetCardinality( BitArray bitArray )
{
var array = (uint[]) bitArray.GetType().GetField( &quot;m_array&quot;, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ).GetValue( bitArray );
int count = 0;

for ( int index = 0; index &lt; array.Length; index ++ )
{
count += _bitsSetArray256[ array[ index ] &amp; 0xFF ] + _bitsSetArray256[ ( array[ index ] &gt;&gt; 8 ) &amp; 0xFF ] + _bitsSetArray256[ ( array[ index ] &gt;&gt; 16 ) &amp; 0xFF ] + _bitsSetArray256[ ( array[ index ] &gt;&gt; 24 ) &amp; 0xFF ];
}

return count;
}</pre>
<p>The reflection access to the private field of BitArray isn&#8217;t exactly fast, but I will optimize it later and post the updated snippet right here.</p>
<p>I hope this implementation is as useful for you as it is for me.</p>

	Tags: <a href="http://www.devatwork.nl/tag/faceted/" title="faceted" rel="tag">faceted</a>, <a href="http://www.devatwork.nl/tag/lucene/" title="lucene" rel="tag">lucene</a>, <a href="http://www.devatwork.nl/tag/search/" title="search" rel="tag">search</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2009/02/bitarray-calculating-cardinality/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Lucene.NET and Facetted Search</title>
		<link>http://www.devatwork.nl/2009/02/lucenenet-and-facetted-search/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lucenenet-and-facetted-search</link>
		<comments>http://www.devatwork.nl/2009/02/lucenenet-and-facetted-search/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 12:36:08 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[drill down]]></category>
		<category><![CDATA[faceted]]></category>
		<category><![CDATA[Liones]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=272</guid>
		<description><![CDATA[For my work at Liones I has to implement a Lucene.NET search solution, including drill-down/faceted search. This was pretty hard to accomplish because there wasn&#8217;t much reference material, at least not for C#, but I just finished the first implementation and it works like a charm. I am not going to discus the implementation in [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-274" title="Lucene" src="http://www.devatwork.nl/wp-content/uploads/2009/02/lucene_green_300.gif" alt="Lucene" width="300" height="46" />For my work at <a title="Liones, het internet bureau voor uitgevers" href="http://www.liones.nl" target="_blank">Liones</a> I has to implement a <a title="Lucene.NET" href="http://incubator.apache.org/lucene.net/" target="_blank">Lucene.NET</a> search solution, including <a title="Drill down" href="http://en.wikipedia.org/wiki/Drill_down" target="_blank">drill-down</a>/<a title="Faceted Search" href="http://en.wikipedia.org/wiki/Faceted_search" target="_blank">faceted search</a>. This was pretty hard to accomplish because there wasn&#8217;t much reference material, at least not for C#, but I just finished the first implementation and it works like a charm. I am not going to discus the implementation in detail because I decided to write some articles about it.</p>
<p>For now, I am thinking about the following articles:</p>
<ol>
<li><a href="../index.php/articles/lucenenet/introduction-to-lucenenet-lucenenet/">Introduction to Lucene</a></li>
<li><a href="../index.php/articles/lucenenet/indexing-basics-lucenenet/">Indexing basics</a></li>
<li><a href="../index.php/articles/lucenenet/search-basics-lucenenet/">Search basics</a></li>
<li><a href="../index.php/articles/lucenenet/alternatives-did-you-mean-lucenenet/">Alternatives ( did you mean …)</a></li>
<li><a href="../index.php/articles/lucenenet/faceted-search-and-drill-down-lucenenet/">Faceted search / Drill down</a></li>
<li><a href="../index.php/articles/lucenenet/class-reference-lucenenet/">Class reference</a></li>
</ol>
<p>Let met know if you have got more ideas for articles.</p>

	Tags: <a href="http://www.devatwork.nl/tag/drill-down/" title="drill down" rel="tag">drill down</a>, <a href="http://www.devatwork.nl/tag/faceted/" title="faceted" rel="tag">faceted</a>, <a href="http://www.devatwork.nl/tag/liones/" title="Liones" rel="tag">Liones</a>, <a href="http://www.devatwork.nl/tag/lucene/" title="lucene" rel="tag">lucene</a>, <a href="http://www.devatwork.nl/tag/search/" title="search" rel="tag">search</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2009/02/lucenenet-and-facetted-search/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Designing an Online Shopping Cart, an Architects Tale</title>
		<link>http://www.devatwork.nl/2009/02/designing-an-online-shopping-cart-an-architects-tale/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=designing-an-online-shopping-cart-an-architects-tale</link>
		<comments>http://www.devatwork.nl/2009/02/designing-an-online-shopping-cart-an-architects-tale/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 17:34:53 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Cart]]></category>
		<category><![CDATA[CRM]]></category>
		<category><![CDATA[customer relationship management]]></category>
		<category><![CDATA[Liones]]></category>
		<category><![CDATA[online shopping]]></category>
		<category><![CDATA[payment service provider]]></category>
		<category><![CDATA[psp]]></category>
		<category><![CDATA[shopping cart]]></category>
		<category><![CDATA[technical design]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=256</guid>
		<description><![CDATA[For my work at Liones I am writing a technical design for a shopping cart. The requirements are fairly basic, except for one: the shopping cart must be generic to support any payment service provider (psp) and customer relationship management (CRM) system. Also there might be several different product types in the future, like: subscriptions, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-medium wp-image-262 alignleft" title="Cart" src="http://www.devatwork.nl/wp-content/uploads/2009/02/cart-300x225.jpg" alt="Webshop Cart" width="300" height="225" /></p>
<p>For my work at Liones I am writing a technical design for a shopping cart. The requirements are fairly basic, except for one: the shopping cart must be generic to support any payment service provider (psp) and customer relationship management (CRM) system. Also there might be several different product types in the future, like: subscriptions, downloads, pay per use, etc.. These requirements make the shop very complex and a great challenge.</p>
<p>I started with an investigation on the internet about this subject and I quickly found out that there aren&#8217;t much articles on this topic around, but I found a few very interesting ones though. Next I started to draw some UML diagrams; I added some best practices like the Money class.</p>
<p><span id="more-256"></span>Then it got interesting: <a title="Yvonne Arnoldus" href="http://www.linkedin.com/pub/2/81b/275" target="_blank">Yvonne</a> (a colleague, senior/lead developer) and I were going over my conceptual model and we were adding and shifting responsibilities as we were going. Things went rapid from that point on: object came to the surface, responsibilities were put on the right place and the domain model started to reveal itself.</p>
<p>The next thing we did was to group objects into packages and again there was some debate about in which package we would put certain objects and what the dependencies between the packages were. The debates made the domain model even clearer. We came up with the following packages:</p>
<ul>
<li>Product Catalog (Product information and grouping)</li>
<li>Cart (The actual cart)</li>
<li>Payment Service (Encapsulation of different payment service providers)</li>
<li>CRM (synchronization with back office)</li>
<li>User (User &amp; Profile)</li>
</ul>
<p>I am not going to discuss the packages in detail here because that is not the scope of this post.</p>
<p>Once we wrapped up that session, I drew the new UML diagrams (in <a title="Sparx Enterprise Architect" href="http://www.sparxsystems.com.au/products/ea/index.html" target="_blank">Sparx Enterprise Architect</a>). I made some minor refinements in the model and I set up a meeting with Yvonne and <a title="Gjalt Wijma" href="http://www.linkedin.com/pub/6/250/b8" target="_blank">Gjalt</a> (another colleague, architect) to review the technical design.</p>
<p>As the review session went on, we made a few minor refinements on the design and discussed how certain parts could be implemented. There was one major element that wasn&#8217;t clear: how does the coupling with a payment service provider work? There seem to be 2 categories: synchronous payments and asynchronous payments.</p>
<p>That is where we stand now, we brainstormed on how to tackle the payment problems but that is for part 2!</p>

	Tags: <a href="http://www.devatwork.nl/tag/cart/" title="Cart" rel="tag">Cart</a>, <a href="http://www.devatwork.nl/tag/crm/" title="CRM" rel="tag">CRM</a>, <a href="http://www.devatwork.nl/tag/customer-relationship-management/" title="customer relationship management" rel="tag">customer relationship management</a>, <a href="http://www.devatwork.nl/tag/liones/" title="Liones" rel="tag">Liones</a>, <a href="http://www.devatwork.nl/tag/online-shopping/" title="online shopping" rel="tag">online shopping</a>, <a href="http://www.devatwork.nl/tag/payment-service-provider/" title="payment service provider" rel="tag">payment service provider</a>, <a href="http://www.devatwork.nl/tag/psp/" title="psp" rel="tag">psp</a>, <a href="http://www.devatwork.nl/tag/shopping-cart/" title="shopping cart" rel="tag">shopping cart</a>, <a href="http://www.devatwork.nl/tag/software-architecture/" title="Software Architecture" rel="tag">Software Architecture</a>, <a href="http://www.devatwork.nl/tag/technical-design/" title="technical design" rel="tag">technical design</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2009/02/designing-an-online-shopping-cart-an-architects-tale/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>Dogs eat Homework, Cats eat Source Code</title>
		<link>http://www.devatwork.nl/2008/09/dogs-eat-homework-cats-eat-sourcecode/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dogs-eat-homework-cats-eat-sourcecode</link>
		<comments>http://www.devatwork.nl/2008/09/dogs-eat-homework-cats-eat-sourcecode/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 19:41:45 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[software quality]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=180</guid>
		<description><![CDATA[In short: no they don&#8217;t. Students are making up excuses for not doing their homework and developers do the same when their work isn&#8217;t done either. People, in general, blame anything but themselves for not getting their work done. The truth, however, is that everyone is responsible for their own actions. As developers we should [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.devatwork.nl/wp-content/uploads/2008/08/funny-pictures-cats-computer-blue-screen-death.jpg" rel="lightbox[180]"><img class="alignnone size-medium wp-image-182" style="margin: 4px 4px 0px 0px;float:left;" title="funny-pictures-cats-computer-blue-screen-death" src="http://www.devatwork.nl/wp-content/uploads/2008/08/funny-pictures-cats-computer-blue-screen-death-300x211.jpg" alt="" width="300" height="211" /></a>In short: <strong>no they don&#8217;t</strong>. Students are making up excuses for not doing their homework and developers do the same when their work isn&#8217;t done either. People, in general, blame anything but themselves for not getting their work done.</p>
<p>The truth, however, is that everyone is responsible for their own actions. As developers we should provide solutions instead of excuses. Of course we are allowed to make mistakes or an error in judgment, but we have to admit that honestly and try to offer options.</p>
<p>We can blame clients, project leaders, our lead developers, our architects, our office manager or that new trainee but in the end you, and only you, are responsible for your own work.</p>
<p>So next time you think about making up an excuse, think about solutions first. You will sound smarter that as a matter of a fact you will be smarter!</p>

	Tags: <a href="http://www.devatwork.nl/tag/software-quality/" title="software quality" rel="tag">software quality</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2008/09/dogs-eat-homework-cats-eat-sourcecode/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Python, without using Python</title>
		<link>http://www.devatwork.nl/2008/08/python-without-using-python/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=python-without-using-python</link>
		<comments>http://www.devatwork.nl/2008/08/python-without-using-python/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 19:19:01 +0000</pubDate>
		<dc:creator>Trilobyte</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[architecture]]></category>

		<guid isPermaLink="false">http://www.devatwork.nl/?p=178</guid>
		<description><![CDATA[Today I faced a problem at work: I had to come up with a flexible, extendable architecture for a XML-RPC client service application. Both the client and server code had to be integrated into existing applications which makes the impact of introducing new message handlers painful if not designed properly. While thinking about those requirements [...]]]></description>
			<content:encoded><![CDATA[<p>Today I faced a problem at work: I had to come up with a flexible, extendable architecture for a XML-RPC client service application. Both the client and server code had to be integrated into existing applications which makes the impact of introducing new message handlers painful if not designed properly.</p>
<p>While thinking about those requirements I quickly thought of a concept I saw in Python: Try to call find a callable method, otherwise do the default action. In Python you can use &#8216;getattr(&#8230;)&#8217; to get a possible method of a class and with &#8216;callable(&#8230;)&#8217; you can check if the method is actually a method.</p>
<p>You get something like this on your dispatcher object:</p>
<pre class="brush: python; title: ; notranslate">def Dispatch(self, methodName, arguments=None)
   method = getattr(self, methodName, None)
   if callable( method ): method( arguments )</pre>
<p>I implemented this extensible architecture in exactly the same way. It was fairly easy to do, painless and it is extensible.</p>
<p>Learning multiple programming languages/concepts pay off!</p>

	Tags: <a href="http://www.devatwork.nl/tag/architecture/" title="architecture" rel="tag">architecture</a>, <a href="http://www.devatwork.nl/tag/python/" title="Python" rel="tag">Python</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.devatwork.nl/2008/08/python-without-using-python/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

