Design Patterns

I've been hit with the question "what do you know about design patterns?" more than once, and decided to dig through and refresh some of that on my break today. So, I wound up on Wikipedia, browsing through the Design Patterns article, and pulling a book from the shelf as well.

Design patterns are useful concepts, but my introduction to them was terrible. The definitive text on this one is "Design Patterns: Elements of Reusable Object-Oriented Software", with authors referred to as the "Gang of Four" (GOF). I picked this book up sometime after 2000, after stumbling over an interview question. The book was easily the definitive text in 1995, when it was published, and continues to show up in software engineering curriculum.

There are two problems with it.

  1. The examples are dated. C++ is no longer the dominant OOP language; Java took a big bite, and C# has taken another chunk. C++ is still relevant, but Java and C# devs are going to have problems with pointer-based objects and explicit memory allocation.
  2. The descriptions are *incredibly* verbose. Yes, I realize it's a reference book, but the Iterator pattern is 22 pages of text. That's "an object that iterates over a list". This makes for a fine reference text, but for learning and/or getting an overview of the subject, this book is Not For The Efficient.
The Singleton pattern is seven pages in GOF. "Ensure each class has only one instance, and provide a global point of access for it." Here's the non-thread-safe Java example:

public class Singleton {
// One global instance of the class
static Singleton instance;
// One private constructor, so no other code can call it
private Singleton() { ; }
// One way to get the global instance
public Singleton getInstance
if (instance == null) { instance = new Singleton(); }
return instance;

// And whatever code may be useful.

No comments: