If you are relatively new to programming you may be asking yourself who gang of four is and what they have to do with design patterns. In this article, I will briefly cover what designer patterns are, benefits to learning them, and how to get started!
Gang of Four (GoF)
Gang of Four Design Patterns is the collection of 23 design patterns from the book “Design Patterns: Elements of Reusable Object-Oriented Software”. This book was first published in 1994 and is still considered one of the most popular books to learn design patterns today. The gang of four authors, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides, initiated the concept of Design Pattern in Software development. These authors are collectively known as Gang of Four.
As they reviewed code systems they were working on, the GoF began noticing patterns in problems and the solutions to them. Since these solutions to common repeating problems were being repeated over and over in various projects, they began putting a name to them to describe the solutions in detail. Over time and after much trial and error, they came up with 23 patterns and described it in their book.
Essentially, design patterns are proven solutions to commonly occurring problems in software design and are like pre-made blueprints that you can customize to solve a recurring design issue in your code. Not only are design patterns useful, but are considered best practices by experienced object-oriented software developers.
What Design Patterns Are NOT
Design patterns are NOT algorithms. You can’t just select a pattern and paste it into your program like a library because it is not a specific piece of code. Design patterns are a more high-level description of a solution that are meant to provide a guidance on structure, relations and hierarchy of an object as well as classes and interfaces in the application.
In other words, they are a way of thinking about abstraction rather than the underlying data. Although there are dozens of design patterns it is important to note that they do not solve every problem. Reusing design patterns help prevent subtle issues which may cause major problems, so even if you may choose the lesser option it is better than coming up with a different solution on your own.
Benefits of Patterns
- Familiarity with design patterns help make it easier to recognize it in a code and get the gist of it without reading every line
- Helps us communicate effectively with other developers at a more abstract level. You can use the name of the pattern to express ideas and solutions rather than providing a lengthy explanation or writing a lot of code to convey the same message.
- Makes you a better designer because you will learn how to build reusable, extensible and maintainable software regardless of the programming language you use or application you are building.
- Helps us learn and use new frameworks faster because these design patterns are ubiquitous in the coding world. So, if you take the time to study design patterns, do not be surprised if a new library you are learning looks familiar (perhaps with different syntax) as a result of this knowledge.
When NOT to Use Design Patterns
Although design patterns are very useful, do not use them if they make your code more complex. They are meant to simplify code for you, so make sure you understand the pattern well. A common pitfall that haunts many novices who have just familiarized themselves with patterns try to apply them everywhere, even in situations where simpler code would do just fine. As a result, it is often advised to practice it in isolation before using it in production code.
Ready to Learn?
It is often recommended to first solidify your skills by practicing basic programming principles, algorithms and data structures. It is vital to understand the fundamentals of this paradigm by first being comfortable with object-oriented programming. Some of the fundamentals include encapsulation, abstraction, polymorphism, inheritance and composition.
You also do not need to learn every single pattern there is or learn them in any particular order. However, it may be beneficial to start with the most common design patterns to understand what other developers are talking about. By starting shallow and broad, you can get some idea of the different patterns and what they do before diving deeper into a particular pattern that interests you.
Design Pattern Categories
There are many other unofficial and undocumented patterns out there that you might find useful in certain situations outside of the classic 23. However, all patterns can be categorized by their intent, or purpose. The book covers three of the main groups of patterns, which I will go into more detail in the next blog.
- Creational Pattern
- Structural Pattern
- Behavioral Pattern
In conclusion, design patterns are universal to every object oriented language. They are agreed terms improving code readability for developers and architects who are familiar with these patterns. Learning just a few design patterns can help improve office communication, making it simpler and more precise to discuss possible solutions using patterns that your team understands rather than describing the solution piece by piece every time. Start by understanding some of the more common design patterns, practice them in isolation and remember the KISS principle when implementing!
You Got This 😎