DEV Community

Cover image for Get good fast. Learn Design Patterns.
Brent Dalling
Brent Dalling

Posted on

Get good fast. Learn Design Patterns.

disclaimer: This is an opinion.

Recently I've run into some situations on code-help servers or development communities that are easily solved by understanding some fundamental design patterns. Lacking this knowledge can lead to the infamous head-banging-on-desk situations. So, let's explore the purpose of design patterns, where they came from, why they're still used, and how you can learn them for free.

Design patterns are development patterns that arose when developers found themselves trying to solve specific design problems. Specifically, they noticed some... wait for it... patterns. They realized the strategies they used to solve problems were applicable in more than one situation and solved pretty complex problems. By documenting these patterns they aimed to help other developers to overcome these technical challenges more easily and advance the career field.

The first design patterns book was called "Design Patterns: Elements of Reusable Object-Oriented Software" and was written by four individuals since dubbed "The Gang of Four". Their book shaped software education and development since the publication. This book as been commonly used in university level educations and even read by the self-taught programmer. The concepts they discuss and the way the address, explain, and catalog each of the main 23 patterns was simple, straight to the point, and provided rich context to the patterns that reduced the need for developers to "self discover" the concepts.

Consequently, the book the Gang of Four introduced has since helped developers of all levels to understand, troubleshoot, implement, and improve software systems using the base concepts provided in the book. There's no doubt these patterns have played an important role in the evolution of the software industry.

In the age of meta frameworks, libraries, and partial solutions do you really need to learn it? It's 23 more concepts to learn, conceptualize, and apply before setting out on your software career after all. Can't you get by without learning these? The short answer: you don't need to learn it do write software. The most realistic answer: while you don't need it you will improve your ability to write clean, performant, and concise software by understanding the basics of code design patterns.

Let's explore how these help you and why developers still choose to use them today. Let's imagine I was asked to create a two way communication system between two completely unrelated classes. To the junior developer this may be vexing. To the senior developer they'd just use callbacks or lambdas in most languages. That way they pass the data to where it needs to go. But, what if there's a more efficient way of handling this?

Introducing one of the twenty-three concepts: the Observer Pattern. Instead of the class supplying data having to be aware of the callback and how to handle it you can use event based programing and simply register a callback to the class issuing the events. Then, when an event is fired on the observed class, the listener can do whatever it likes with the supplied data. In code we typically call this the pub/sub model and it's heavily used in the HTML DOM and JS.

This pattern is also heavily used in communications between two systems. Such as when using websockets. The Observer registers to listen to a specific event on a socket. The Observer takes on the role of the subscriber and waits for the specific event to come down the pipe from the publisher (the observed). This model allows both systems (remote and local) to have no knowledge of one another or how to handle the callbacks / classes. This concept is a loose form decoupling.

So we've established that these patterns are heavily used and we briefly examined one of the many patterns that developers see and use without really knowing what it is. So how do you learn these? Do you need to attend a university? Buy a 30 year old book for $40? Sell your kidney? Well, no. You can read about each of the patterns for free at any of the resources below. I seriously recommend reading at least some of them. And remember, all developers at every level of their career must continue their education to become more effective.

Free Resources

https://refactoring.guru/design-patterns
https://www.freecodecamp.org/news/tag/design-patterns/

Paid Resources

https://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612
https://refactoring.guru/design-patterns/book

If you found this helpful please leave a like and bookmark. Please leave a comment! Let's discuss this topic! If you spotted a problem with the information provided please leave a comment and let me know. Let's have a healthy discussion! Thanks for reading!

Top comments (0)