Dev @ Work

A day in the life of a developer

Asynchronous Payment Provider Implementation Pattern

March 17th, 2009 by

PaymentToday 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 UML diagram below; you will notice that there are actually two flows:

  • One synchronous, which guides the user trough the payment screen
  • One asynchronous, which notifies when the payment state changed (payment is confirmed or canceled)

Read the rest of this entry »

Designing an Online Shopping Cart, an Architects Tale

February 16th, 2009 by

Webshop Cart

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.

I started with an investigation on the internet about this subject and I quickly found out that there aren’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.

Read the rest of this entry »

Model View ViewModel ( M-V-VM )

February 15th, 2009 by

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 came up with back then is to make the domain model aware of the need to bind and implement specific functionality like [System.ComponentModel.INotifyPropertyChanged]. 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!

The solution: Model-View-ViewModel pattern

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 – View – ViewModel (MVVM or M-V-VM).
Read the rest of this entry »

Python, without using Python

August 26th, 2008 by

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 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 ‘getattr(…)’ to get a possible method of a class and with ‘callable(…)’ you can check if the method is actually a method.

You get something like this on your dispatcher object:

def Dispatch(self, methodName, arguments=None)
   method = getattr(self, methodName, None)
   if callable( method ): method( arguments )

I implemented this extensible architecture in exactly the same way. It was fairly easy to do, painless and it is extensible.

Learning multiple programming languages/concepts pay off!

Monorail in a Castle

October 9th, 2007 by

Castle Monorail

This post is not about some train riding one single track and a big fortified building but about the Monorail MVC (Model View Controller) framework of the Castle Project.

This is not going to be an introduction to Monorail but rather a story about my workflow for this particular project. Although I might write an article about Monorail in the future, for now I will point you to the Castle Project website for information about Monorail.

Last week I had to build a web application for the Van der Werff project, which allows users to view project information online and report malfunctions. The access to the information must be protected from anonymous users and only be accessible for authenticated users. The project information comes from the WCF web service, which also provides the security.

In the next paragraphs you can read how I implemented the application.

Read the rest of this entry »

Interception Magic

September 27th, 2007 by

Hello, how are you? I am fine, thanks for asking. :S, anyway, in this post I will tell you about my first experience… with Windsor Castle interceptors that is. This morning, way to early, I tried to solve an access control problem: I needed to protect several WCF web services from unauthorized users. I was not very awake at the time so I came up with an easy, yet elegant, solution: use interceptors.

What are interceptors you might think, well, interceptors are class which intercept method calls for other classes. The purpose is to implement a common action, like: logging or authorization, they basically act as proxies. Castle Windsor allows you to configure interceptors in the application configuration file which solved my problem of having to modify all the service code myself.

Writing an interceptor for the Castle Windsor container is actually a simple and straightforward process: Create a new class and implement the IInterceptor interface which defines one single method: Intercept(IInvocation). The only thing left to do is to configure the component on which you want to apply the interceptor. That is it.

I am not going to explain all the details now, however I might write an article in the near future. That is it for now, until next time.

About Interface Driven Design

July 29th, 2007 by

Interface Driven Design is a development methodology where you first create an interface for your object and later implement the object itself. The interface acts as a contract between the object you are developing and its consumers.

There are several advantages:

  • Flexibility, you can change the underlying implementation of an object without updating its consumers
  • Easier to refactor
  • Easier to use in combination with Dependency Injection and Inversion of Control, which allows you to swap implementations
  • Easier to test. Interfaces can be mocked more easily than concrete objects

I use IDD in one of my current projects and I must admit that I like it very much. It allows me to make decisions, like how to instantiate the object, later on in the development cycle when I am ready for it

For example: I was working a Unit of Work class which consumed a validation service. I had no idea how to implement the validation service and I did not want to think about it yet. However I knew what the contract between them was, so I could write that interface and use Rhino Mocks to mock the validation service which allowed me to finish the implementation of the Unit of Work class.

Rhino Mocks, by the way, is a fantastic framework for mocking objects written by Ayende Rahien. I started using it today and I loved right away. It is incredible easy to use and very user friendly. You can find the website of the product here. Expected more posts about it in the future!

Of course you can combine IDD with other development methodologies like Test Driven Development, which is my current way of working.

It Has Been a While

July 26th, 2007 by

That is most certainly true; my last post was about a week ago. I have been very busy, both professionally and personally. However, today I have time to write for my blog and for some projects I have been working on.

Professionally I have been very busy with re-implementing an application to leverage to power of DDD (Domain Driven Design). The application contains objects, users and permissions, the difficult part was to come up with a design to handle permissions for the different objects. At the moment the architecture is highly experimental, but when I am finished with it I will publish a sample on this weblog, so keep an eye out.

Personally I have been spending a lot of time with my girlfriend, since she is going on a 2 week holiday this weekend. This weekend I went with her, her sister and her friend on a weekend trip in Venlo. We had some great time there; I wish that could last forever. Unfortunately all good things end. Anyway, my journey to find 5 minutes beauty each day is going absolutely amazing: It gives me great joy and happiness in my life.

Today I am going to work on a very interesting new concept we came up with in a meeting last week. It is an effort to present the truth about a lot of things in a simple, yet comprehensible, way. We want to provoke discussions on various subjects, like: the ‘Al Gore’ discussions about the environment. I do not know where it will lead, how we are going to do it, but I am very existed about it and I believe that it is an opportunity to change the world. I will keep you posted on this!

Strategy Pattern & Design by Contract

June 17th, 2007 by

In this post I will explain how you can implement the Strategy pattern using Design by Contract without violating the DRY (Donâ??t Repeat Yourself) principle. The strategy pattern can be used to expose algorithms which are interchangeable and can vary without the client even knowing it. Design by Contract is a programming method where you define contracts for functions with pre and post conditions.

The violation of the DRY principle occurs when you are implementing the strategy pattern, The abstract base class of the strategy defines a pure virtual/abstract function. The concrete strategy implementation class, â??Aâ??, implements the function. When you implement the function you need to write code for the pre and post condition checks. The problem occurs when you need to implement another strategy implementation class â??Bâ??. Again you need to write the pre and post condition code. That is a clear violation of the DRY principle as well as wrong implementation of the strategy pattern: because it states that all the strategies should behave in the same way, although it is not a violation, programmers might write exactly the same code twice, but it does not rule out the possibility.

Now that I have defined the problem it is time to look at the solution. The solution is quite simple and looks really neat in my humble opinion.

First you need to create a new base class for all the strategy implementation classes: The class contains two methods: One public sealed/final function which is used by the client and one protected abstract/pure virtual function which is used for the actual strategy implementation. The signature of the two function must be exactly the same.

The public function performs three steps, run the pre conditions, call the strategy implementation function and run the post conditions. The protected abstract/pure virtual function is implemented in the concrete strategy classes. The class now looks like this:

public abstract class AbstractStrategy
{
	public void			Perform()
	{
		// pre condition code

		// call actual algorithm
		ExecPerform();

		// post condition code
	}
	protected abstract void	ExecPerform();
}

This code does implement strategy pattern correctly, guarantees that the pre and post conditions are run exactly the same for all concrete strategies and does not contain any duplicate code: smart, logical and beautiful.

Inversion of Control

March 26th, 2007 by

Ik ben sinds enige tijd bezig met het ontwikkelen van een softwarepakket met behulp van een Inversion of Control container en ik ben er erg enthousiast over, vandaar deze post.

Read the rest of this entry »