Issue #49: Object-Oriented Programming,  Library

The Gang Of Four

Many different things bear the name “Gang of Four”; however, in this case, we are going to talk about a major bestseller in the history of computer books: “Design Patterns: Elements of Reusable Object-Oriented Software” by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. There is a high probability that every reader of this article owns, has read, or has at least skimmed through the pages of a GoF book once or twice. The book has been reprinted dozens of times (40 times at least until 2012.) It has been the subject of uncountable articles, videos, panel discussions, and, yes, also attacks.

We are not going to delve into the book’s contents, structure, or legacy; plenty of commentators have talked about that. Instead, we would like to focus on the various ways the book has been helpful to quite a few generations of computer scientists and software engineers. We will also not dive into the influence of Christopher Alexander’s book “A Pattern Language” on the Design Patterns movement. Lots have been said about that. Instead, we will point you to Mr. Alexander’s talk at OOPSLA 1996.

It is worth a mention (at least) that the GoF book dwarfed another excellent treatise on the subject, also named “Design Patterns for Object-Oriented Software Development,” written by Professor Wolfgang Pree and published the same year (1995) by the same publisher (Addison-Wesley) using code examples in the same language (C++.) Pree’s book mentions Erich Gamma’s 1991 thesis at the University of Zürich as major influence and inspiration.

There are many reasons to think that the GoF book has been influential; after all, even if you do not like Stephen King novels or John Grisham novels, it is undeniable there are a lot of people who enjoyed them. So many, in fact, that Hollywood found on them quite a few successful blockbuster ideas. Yet, at the same time, purists will attack King and Grisham, arguing that they are neither Walt Whitman, Harper Lee, James Joyce, John Steinbeck, or Virginia Wolff. So be it; there is room for many different writers and writing styles.

We should apply the same criteria to computer books. We have already compared Donald Knuth to J. R. R. Tolkien; let us try to find a similar analogy to “Design Patterns.”

Structurally speaking, we can read this book in two movements; the first section contains some interestingly advanced (well, at least for 1995) observations on OOP analysis and design. The second section consists of the (in)famous catalog, describing 23 different design patterns. Instead, let us reshuffle the patterns and group them differently.

In our first category, we will place those patterns that proved to be very useful in many contexts: Visitor, Builder, Template Method, Observer, Decorator, Command, Adapter, Façade, and others. In the second group, those that did not: when was the last time you applied the Flyweight, Memento, or Interpreter in your full-stack web application? Finally, there is a small group of eternal outcasts composed of Singleton, Abstract Factory, and Factory Method.

Now for the hard part: these groups are related to Stephen King’s novel characters. Yes, you read right. We are pretty sure you did not see that one coming.

Each of the actually helpful OOP patterns in the first group reminds this author of Paul Sheldon, the unfortunate protagonist of “Misery.” They are somehow trapped by a group of crazy nurses called Java, C++, and C# (stuck in version 1.0), forcing them to generate lots of classes grouped in curious architectures, all while heavily sedated, unable to escape, and begging for help. At some point, a dynamically typed police force consisting of Ruby, Python, and JavaScript frees them from this ordeal.

The second group is akin to John Smith, the main clairvoyant character of “The Dead Zone.” These patterns are constantly aware of a horrendous possible future; they choose to act to prevent it from happening but disappear forever as soon as they jump into action.

Finally, the last group consisting of Singleton and the Factories are like “Carrie,” mocked and bullied by a whole industry in a neverending prom, one which saw them covered with blood and laughed at every coronation ceremony. Yet, they persisted, and every so often, one of them reappears in our code and on our minds while they scream with rage and blow up our unit test suites with all their might in a catastrophic explosion of anger. Well, particularly Singleton, anyway.

Ironically enough, the Gang of Four was first humorously indicted of various sins by their peers; this happened at OOPSLA 1999, where a “show trial” was held in which the authors were found guilty. One of them, Richard Helm, confessed in absentia, discharging his responsibility upon the other three accused.

Unfortunately, ten years after the book’s publication, John Vlissides passed away at 44, more or less at the same time when “Head First Design Patterns” changed the game of computer books forever.

Despite all the abuse the GoF book has suffered during the past quarter century, it remains a vital and utterly influential piece of work. Sure, we could replace many of these patterns with functional programming constructs, Aspect-Oriented Programming, or what-have-you paradigms. Still, the careful depiction of each pattern in this colossal work as a coherent body of objects interacting at runtime has dramatically changed how we relate to software.

Whether we like it or not, design patterns give names to groups of objects; and Phil Karlton said, naming is one of the hardest problems in computer science. We needed this taxonomy, and it proved helpful, if anything, to highlight the infinite flexibility of software and our minds.

Cover photo by the author.

Donate using Liberapay

Adrian Kosmaczewski is a published writer, a trainer, and a conference speaker, with more than 25 years of experience in the software industry. He holds a Master's degree in Information Technology from the University of Liverpool.