Monday, April 06, 2009

For me, who have left a part of his heart with XP, Vista defragmentation tool is a sore disappointment. There are may be some clever algorithms behind the scene, but I feel insecure, staring at incomprehensible message "Defragmentation is running. It may take minutes or hours...". Bill's balls! Why these guys slumming me with so much of unwanted graphics, would cut off the actually useful one?!

Saturday, April 04, 2009

Fluent interface is not as famous of a pattern as the Strategy Pattern but average developer encounters it far more often, sometimes not even realising it. Take C# String object for example: MyString.ToUpper().Trim().Replace("a", "A") – that’s a pretty much daily code.

In a sense Fluent Interface has an application to the state of the object similar to one which Decorator Pattern has to the structure of the class. Some kind of State Decorator Pattern – although the idea of the Fluent Interface is to produce deterministic results, while Decorator potentially could be designed in opposite way (though I can’t think of the reason as yet).

and you’re about to build unit tests which will evaluate business rules around any single property and even different combinations of them. Generating test objects may be tedious job which is often assigned to Test Set Up methods. As you progress, you may notice that some of the helper methods are useful between test modules and then you decide to extract this functionality to helper classes, which areevil.

Instead it is better to go the right OOP way and create classes which expose generic functionality and provide us with concrete instances of out domain entities to test.

Essentially it is an implementation of Builder and Factory (or Object Mother) patterns. Every domain entity’s property has a corresponding method in the relevant Data Builder class. Some of the properties, which we are not too much concerned about (like Name in the example) can be simply set to some default values.

Age method deserves a little bit of explanation. Of course, keeping DateTime Date Of Birth is the right thing to do. But from our testing prospective (at the very least) we will be interested in a Student’s current age. If we wouldn’t use the Age method in its current form, we would be forced to mock the Current Date-Time for our test harness, otherwise some of our tests would become invalid with time.

Notice, that in this Fluent Interface implementation the StudentDataBuilder object is immutable. Some other versions pass the same instance throughout all the methods. It may happen, that some testing scenarios can yield weird results in this case so it is better to keep them guaranteed unrelated. In this case we can safely “branch” objects for a different tests: