Design Patterns Series, Day 1: Welcome!

Welcome!

Today, Safari is kicking off its Design Patterns Series. Over the course of the next seven days, you’ll become familiar with object-oriented Design Patterns by working through some of the materials that are available to you through Safari.

The Plan

Throughout the this series, the main readings will come from Head First Design Patterns. It’s currently Amazon’s number one best seller in Computer Systems Analysis & Design, and after you read a few chapters, hopefully you’ll see why. Its style is very conversational, making it reasonably easy (and even fun) to read. The technical content is sound. But more importantly, it puts Design Patterns into context: it ties them to the basic principles of object-oriented design.

After reading a chapter from Head First, you’ll skim the description of the same pattern in Design Patterns: Elements of Reusable Object-Oriented Software. This is the original Design Patterns book, the book that named and defined each of the Design Patterns for the first time. Its authors — Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides — are often called the “Gang of Four,” so this is referred to as “The GoF Book.” The descriptions in this book are authoritative: if you want a definitive answer about a pattern, this is the first place you should look.

If You Don’t Know Java

The main readings will come from Head First Design Patterns. It uses Java throughout the book, but C# programmers should have no trouble understanding it. Secondary readings come from the GoF book, which primarily uses C++, occasionally describing issues arising in Smalltalk. There are books on Safari that cover Design Patterns in C#, Objective-C, JavaScript, PHP, Python, and Ruby. Each day, we’ll give pointers to the relevant chapters of those books. So if Java isn’t your style, feel free to focus on the relevant chapters from one of these books instead, and then skim the suggested reading afterwards.

Dive in Head First

Without further ado, let’s start learning about Design Patterns! Today’s main goal is to learn what Design Patterns are exactly and why they’re useful.

Start by reading the first part of chapter 5 from Shalloway and Trott’s Design Patterns Explained: A New Perspective on Object-Oriented Design (second edition), which gives an excellent, high-level overview of why Design Patterns are worth learning and where they originated from:

Do you understand what Design Patterns are? Check yourself by reading the first part of chapter 1 from the original Design Patterns book, a.k.a. “the GoF book,” to see how the Gang of Four describes the concept:

Skip the section “Design Patterns in Smalltalk MVC” and stop when you get to “The Catalog of Design Patterns.”

Test Your Knowledge

Each day, we’ll post two or three questions about the readings. Don’t worry, you can’t fail (and no one’s recording your answers unless you are!).

Usually, the questions will reiterate a couple of interesting or subtle points that you might have missed (yes, sometimes important details get “buried” in a chapter and are easy to overlook). They’re not a comprehensive test, and they’re not a certification exam. Sometimes the questions will put a concept from the chapter into a broader context, and they’ll point you to other resources on Safari where you can learn
more about that concept.

So for now, try out these questions about Design Patterns:

The Gang of Four was influenced by Christopher Alexander. Who was he?Answer

Interestingly, this was not in the reading from the GoF book; it was in the reading from Design Patterns Explained. Christopher Alexander was an architect who authored two notable books, The Timeless Way of Building and A Pattern Language. (No, they’re not available on Safari. Sorry!)

Design patterns are not about designs such as linked lists and hash tables that can be encoded in classes and reused as is…. The design patterns in this book are descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.

Consider the design principle, “Program to an interface, not an implementation.” If a Java program does not contain any interface definitions, does it violate this principle?Answer

Not necessarily. In the statement of that design principle, “interface” refers to a general concept, not the Java interface construct. The Head First reading describes this: “‘Program to an interface’ really means ‘Program to a supertype….’ You can program to an interface, without having to actually use a Java interface.”

Next Time

That’s all for today! Starting tomorrow, we’ll begin studying some of the major Design Patterns in detail. We’ll focus on two patterns each day through the end of the Design Pattern series. On the last day, we’ll point you to the wide variety of resources on Safari that you can use to continue learning about Design Patterns in more depth.

Tomorrow, we’ll begin by looking at a two patterns that are used ubiquitously in user interface programming: the Observer and Decorator patterns.