Category: Design Patterns


Design Patterns - why read books?

July 20th, 2008 — 09:12 am

Most developers come across a reference to the GOF design pattern book at some point during their career.

Others refer to the Head first patterns book, or other similar books on the subject.

My advise: Instead of buying another paper weight and spending a lot of time extracting little information from a lot of pages (never could find the search option), go to the Dofactory design patterns web site. You can find information there easily and besides the theoretical data there are “real world” code samples in C#.

And if you are willing to spend some money, you can get further access to C# optimized code, as some patterns incredibly simple in C#:

So before spending your weekend with a technical book, take a look at the online alternative.

Comment » | Design Patterns

Generic Singleton Factory

March 9th, 2008 — 03:03 pm

This is a great way to create a Singleton instance of an exiting class without needing to specifically design it as a singleton:

// Singleton factory implementation
public static class Singleton where T : class
{
static Singleton()
{
// create the single instance of the type T using reflection
Instance = (T)Activator.CreateInstance(typeof(T), true);
}
public static T Instance { private set; get; }
}

class Program
{
public static void Main()
{
// test
Console.WriteLine(Object.ReferenceEquals(Singleton.Instance, Singleton.Instance));
}
}

1 comment » | Design Patterns, Useful .Net classes

Design patterns: I wouldn’t bother reading the GOF book

February 16th, 2008 — 03:17 am

I have to disagree with Gil’s (welcome to the blogosphere) recommendation regarding the classic DP book:
I found it very hard to read, focusing on theory (as opposed to practice), and laking use of .Net framework features (since it was not written for .Net users).
If you are a .Net programmer and want to learn and use design patterns, I recommend going to dofactory.com - clear, real-world examples meant for C# developers.

Comment » | Design Patterns