Archive for the 'Design' Category
Command Pattern with Notification Event Delegates
Monday, September 19th, 2011
Here is a nice little code I did recently, where the Command Pattern is used with a notification observer like pattern. First of the Command Pattern, a simple interface for task with an execute method ?View Code CSHARP1 2 3 4 5 6 7 public interface ITask { /// <summary> /// Execute the task /// [...]
Ottawa IT Code Camp – Unit Testing with Mocking Framework
Saturday, April 16th, 2011
Thanks to everyone who came to the code camp today, I will get those Typemock license to the 2 winners. Here is the code if anyone is interested https://github.com/taswar/Ottawa-IT-Code-Camp-Unit-Testing-with-Mocking-Framework Here is the presentation. Mocking a Unit Test Story on Prezi
Stubbing out ServiceLocator for unit testing
Wednesday, June 30th, 2010
There are certainly many ways to stub out dependency, using constructor injection, etc etc. Here is one way to quickly stub out ServiceLocator rather than implementing ServiceLocatorStub. Lets say you have code that uses a helper and the dependency is not quite the responsibility of that object but its the sub object that uses it. [...]
Learn The Sprout Method for adding new functionality
Monday, August 31st, 2009
In this Learn Series I am going to write about the Sprout Method which is in the book “Working Effectively with Legacy Code by Michael Feathers“, all I have to say is what a great book if you don’t have it, you should pick it up asap. Sprout Method is a technique that one can [...]
Be mindful of the Null Pattern
Monday, August 17th, 2009
Last time I blogged about “Learn the Null Pattern“, but I forgot to mention one thing about the Null Pattern. That is you have to be mindful of it. For example ?View Code CSHARP1 2 3 4 5 6 foreach(var id in IDList) { var employee = db.GetEmployee(id); salary = db.CalculateSalary(id); employee.Pay(salary); } The code [...]
Learn the Null Object
Tuesday, June 2nd, 2009
Today, I thought I would mention the Null Object design pattern, its an object that provides intelligent do nothing behavior, hiding the details from its collaborators. So what does this mean??? Before I tell you what it means, lets see an example of how often you might be seeing code that is checking for null. [...]
Learn the Observer Pattern with Event/Delegate
Monday, May 11th, 2009
As promised here is the version of observer pattern with Event/Delegate. Personally I am not a big fan of this solution, although it does remove quite a bit of code and show how to use a push model with the observer pattern. Next time around I will show a more elegant solution by using Event [...]
Learn The Observer Pattern
Monday, May 4th, 2009
I am starting to write a series of blog post which would be named “Learn {tagline}…..” In these series I would post things about design pattern, programming methodologies, skills etc etc For today, I will start with my favorite Design Pattern. The Observer Pattern. I would first state out what the GoF book, states as [...]
Extract and Override refactoring technique part 2
Friday, April 17th, 2009
This is part 2 of Extract and Override technique. You can find part 1 in my previous post. I am going to show another technique by using Factory Method to break dependency in your code. *WARNING* *WARNING* Before I begin I would like to say all these techniques are not the best design but they [...]
Law of Demeter (Principle of Least Knowledge)
Friday, April 3rd, 2009
The Law of Demeter (LoD), or Principle of Least Knowledge, is a design guideline for developing software, particularly object-oriented programs. (wikipedia) While everyday working on code that was written by lazy coders or junior coders I see a lot of violation of this law. I think every programmer should know the Law of Demeter by [...]
