The value of design patterns
There’s a “new” post out by Anthony Ferrara, called Beyond Design Patterns In this post, Anthony boils down most well known patterns into a single goal, and articulates that moving past design patterns is best for everybody. He says,
Are design patterns useful? Absolutely. But I’ll assert that once you understand OOP and object communication, the patterns will “fall out” of the code you write. They come from writing OOP.
Anthony makes some great points in his article, and I highly encourage you to read it. But I want to address the perspective that he puts forward, which is that worrying about design patterns is less important than worrying about writing great object oriented code.
The analogy of learning a language
Think back to when you learned a new language. Not a programming language, but a foreign language. I recently traveled to France, where I wrote about my experience gaining a bit of knowledge of the French language and how to do basic things like ask for a loaf of bread.
In many ways, design patterns are frameworks just like sentence structures we learn about in foreign languages. Design patterns provide, especially for the less experienced developer, the ability to compose and communicate with objects (and other developers) in a cohesive, meaningful way.
Of course, to the native speaker, constructing sentences that contain one subject and one verb seems an unusual thought pattern. We naturally have the ability to consider more complex language concepts without considering the underlying building blocks. If I asked you to diagram this sentence, you might remember how to do it from when you were in grade school (assuming English is your first language). But for someone learning to speak English, they would be intimately familiar with the process of sentence diagrams and identifying subject, verb, and other parts of the language.
Fluency might mean less of a reliance on prepackaged form – but the form is still there
Of course, once a language learner becomes fluent, their focus on constructing sentences and phrases in such a rigid way begins to fade away. They begin to frame their thoughts into more complicated phrases, start understanding idioms and slang, and even take advantage of incomplete sentences to express some thoughts.
This is very similar to a junior developer who learns a design pattern, but learns enough object oriented programming that they no longer need to rely on the established patterns to accomplish their tasks. They instinctively know what is required of them, and clearly understand what tasks they must accomplish. They don’t need design patterns any more than a fluent French speaker needs a sentence diagram to write a letter.
Yet the patterns still exist, in language and in the work of an object oriented expert. In fact, the patterns are usually executed so well that they are no longer rigid, obvious forms but clean, clear, concise and collected efforts to solve problems. Object oriented developers who are experts don’t need to grab the Gang of Four book to find a pattern that fits their problem any more than Earnest Hemingway needed to grab a grammar book to write his novels.
Design patterns are still useful
Yet no one would argue that we should eliminate grammar books entirely. In fact, they are incredibly useful for teaching grammar to children and students of a language alike; understanding how sentences are constructed is a crucial first step towards creating understanding of the language as a whole. Design patterns serve this purpose for object oriented programming.
The Gang of Four express this concept thusly:
It takes a long time for novices to learn what good object-oriented design is all about. Experienced designers evidently know something inexperienced ones don’t. What is it?
One thing expert designers know not to do is solve every problem from fist principles. Rather, they reuse solutions that have worked for them in the past. When they find a good solution, they use it again and again. Such experience is part of what makes them experts.…
An anology will help illustrate the point. Novelists and playwrights rarely design their plots from scratch. Instead, they follow patterns like “Tragically Flawed Hero” (Macbeth, Hamlet, etc.) or “The Romantic Novel” (countless romantic novels).”
The Gang of Four articulates that even writers of great literature follow patterns. Who are we, then, to say that design patterns don’t matter? Indeed, they do matter. They provide a foundation for us to design with, and they provide the inexperienced developer with a tool to help him become more experienced overall. Once he’s experienced, he’ll likely move on from design patterns. But we shouldn’t write them off entirely.