5 min read

Why we need design patterns in programming and where to study them

Software Engineering Manager Pavel Yukhnovich points out the pros and cons of using design patterns and shares useful sources for finding them. The article also contains links to relevant courses. Remember that Anywhere Club members can get a LinkedIn Learning license in 4 simple steps.

Pros

  • Maintainability and readability. Design patterns help us to better understand our code base and make it easier for us to read other people's code. They also help us write more legible and maintainable code, which makes your team’s collaboration much easier.
  • Less code is required, and there is no need to reinvent the wheel. Design patterns help developers today, just as they did yesterday and will do tomorrow. Chances are, the thing you need to implement is not unique, and the solution was defined with some design pattern years ago.
  • Unified tool of communication. Software design patterns are a way to describe and document a design. They are a common language that helps different teams communicate with each other. They also act as a guide for software developers to understand how to solve problems in the future. Patterns can be used also by designers, UX specialists, business analysts, testers, and anyone who wants to improve their work process or improve the quality of their product or service.

Cons

  • Counterproductive reliance. A problem with software design patterns is that they are often used as instructions rather than recommendations. This means that developers start applying them without fully understanding the purpose or the underlying principles behind them.
  • Not always a unified communication tool. We should remember that occasionally, in some programming languages, it might be almost impossible to apply any pattern.

Sources of learning

— There are a lot of resources available these days, and it's better not to rely on just one. Do not pay attention to the publication dates of "must-read" books on design patterns, since the solutions described in them are easily applicable to modern tasks.

Online materials

Refactoring Guru — this is a relatively new site with very high-quality content. Things I like about it include:

  • It's totally free.
  • Detailed and rich structure for each pattern, including: intent, problem, solution, structure, pseudocode, applicability, implementation tips, pros and cons, and relations with other patterns. All of this helps you to truly understand the specifics of each.
  • Real-world analogies: amazing doodles with simple and straightforward explanations eliminate any hesitation you might have about any of the patterns.
  • Pattern code examples are available in 10 different programming languages. So, adepts in Python, TypeScript, Java, Ruby, C#, C++, Go, PHP, Rust, and Swift won't need to spend time repeatedly trying to understand the pattern, bouncing between various resources and books while searching for their preferred language code snippets.
  • All of the materials are available as an eBook in a variety of formats. It has been translated into many languages. However, my long-term advice would be to improve your English so you can read the original versions.

    Discover your English level

    Books

    1. Design Patterns: Elements of Reusable Object-Oriented Software — The Gang of Four is the quartet of authors of the most popular book about Design Patterns. In this and subsequent books, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides outline their vision of how patterns should be used in software development. The book was written to help software developers understand some common problems of object-oriented programming and provide recommendations about how to use the principles of design patterns to write extensible and flexible object-oriented applications. This is not a catalog of patterns, but rather a description of what they are, how they work, and how to use them. It teaches design pattern vocabulary and offers working rules for applying patterns in your own projects, etc.

    If you are new to pattern development, it is better to return to this book later. If you have a Computer Science degree and you have tried this book before, but have not read it to the end, I recommend that you try again.

    2. Head First Design Patterns: A Brain Friendly Guide (2004) and its second edition Head First Design Patterns: Building Extensible & Maintainable Object-Oriented Software (2020) are also widely popular though quite controversial. Both editions are similar, so I will combine my remarks. These book might be appealing to a wide audience of professionals - especially those who are just starting their journey with patterns. It contains side stories, a ton of complementary pictures, crosswords and code puzzles, Java code samples, and 90s photos.

    3. Design Patterns for Dummies (2006) — Another beginner-friendly book about design patterns. It is not as funny as the previous one, but is an absolute must-have for anyone who wants to improve their understanding of the topic. Java code snippets, simple and clear explanations, and occasional references all create a pleasant reading experience.

    4. Learning JavaScript Design Patterns: A JavaScript and JQuery Developer's Guide — My recommendation is to be careful with this book. JavaScript is evolving very quickly, and many things have changed since the book’s first publication. Many code examples are either outdated or can be recreated in a more appealing way using newer versions of the language. Adding MV(?) patterns does not make it better; this block complicates the learning process for beginners, and it can just be skipped. You might also be disappointed with the impact of detailed legacy jQuery information.

    The author of this book, Addy Osmani, collaborated with Lydia Hallie to create patterns.dev. Here, you can find the reimplementation of his book through the new JS syntax (and, for some reason, jQuery examples are back in business again). This whole book is just a chapter in a bigger section, in which he goes pattern by pattern with code examples and nice animations. I strongly recommend having this chapter as a reference point, since it lists the most popular design patterns applicable to JS.

    At the same time, it includes rendering and performance patterns. These two sections are essential for web developers, and most of the examples are applicable to React apps. So, this resource is quite specific and might be confusing for beginners in design patterns.

    Linkedin Learning courses

    — There are many courses available to us. I recommend several of them: entry-level and those that are dedicated to specific programming languages.

    Get a LinkedIn Learning license in 4 Steps

    Conclusion

    — Software design patterns are a powerful tool in your toolbox that can help you overcome common software challenges. They are not a silver bullet, and they will not solve all your issues, but they can be very valuable if you know how to use them. You don't have to learn all of them by heart — just study the theory and then start applying them in practice.