Zachary W. Huang

Home Projects Blog Guides Resume

GoF Design Patterns

In 1995, four authors (known as the “Gang of Four”, or “GoF”) wrote a now-very-widely-known book called Design Patterns: Elements of Reusable Object-Oriented Software. This book documented almost two dozen software design patterns for OOP, and it no doubt has had a large effect on software development as a whole since then. I figured that knowing these patterns could be beneficial to me, so I’ve written a sentence or two summarizing the idea behind each pattern, along with some example code for each.

Note: I am, of course, omitting details like the performance/expressivity trade-offs of each pattern, relationships between different patterns, example use cases, etc. The point of these summaries is so that you (the reader) can get a feel for these design patterns without reading 400+ pages of technical writing and code (unless you want to, I guess). Also, the list below may seem intimidating, but if you have a decent amount of programming experience, you’ve probably already seen many (if not most) of these in the wild, just not with these names attached.

Another Note: It is also important to understand the context in which these patterns were documented and the history behind why they exist. The point is not to stuff your programs with as many design patterns as possible (that’s how you end up with Enterprise FizzBuzz). Rather, I believe it is useful to know about these patterns and their ideas, even if you never end up using them in your code. I’ve written some more thoughts here (it was originally going to be the preface to this guide, but then it got too long).

Creational Patterns

Structual Patterns

Behavioral Patterns

RSS icon github logo linkedin logo

Zachary W. Huang © 2021-2024