Design Patterns: What Are They? Why Should You Care?
I really love to code. And, I'm sure that if you're reading this, you do to. I'm also sure that if you're reading this, you also agree with me that although it's easy to hack your way to code that works i.e does what you want it to do. It's a bit hard to write code that is clean, readable and does not cause you to lose sleep whenever you think about how you're going to have to make changes to that code someday A.K.A "Please don't break the codebase".
So today, we're going to be talking about Design Patterns. Hope you're excited?
What Are Design Patterns?
Design Patterns are typical solutions to commonly occurring problems in the process of Software Design.
In this sense, you can think of a Design Pattern as being the Software Engineering equivalent of a Blueprint as is used in other engineering fields like Civil Engineering.
Now, I would really like to point out the fact that a Design Pattern is not the same thing as an Algorithm. Essentially, where an algorithm is meant to dictate the set of actions that need to be taken in order to perform a task or achieve a goal, Design Patterns are only meant to provide you with the high-level description of how to model or organize whatever solution (algorithm) you come up with. To use an analogy to buttress the point I'm trying to make, if you can imagine an algorithm as being a recipe (list of instructions) to cook a certain dish that you like so much, then you can picture the design pattern to be the technique such as boiling, frying, grilling e.t.c that you would need to use in order to do the actual cooking. A typical design pattern would consist of:
An intent: A description of both the problem and the expected solution.
A motivation: A further explanation of the problem solved and the solution enabled by the pattern in question.
A structure: Depicting the constituent units of the pattern and how each unit relates to the other.
A code example.
Over the years, through analysis of their code by many developers, a lot of design patterns have been discovered and documented. Through careful consideration and analysis by many experts, it was discovered that the many of the design patterns that exist could in fact be clustered into three groups i.e Creational, Structural and Behavioural patterns. The design patterns in these groups possess some traits that aided the classification. I'll talk about these traits and each of the groups at some future date.
Why Should You Care?
Two reasons:
A knowledge of the existing design patterns provide a toolkit of tried and tested solutions to common software design problems. Thus, enabling you to solve all sorts of code design problems that you may face, writing better code in the process.
Could provide you with a quick and somewhat cool way to effectively communicate technical concepts to other developers or your teammates. You could say something like: "Let's put a Singleton at line x in the codebase" and look like a genius in the process. Which is really worth it in my opinion.
Conclusion
So, you've gotten an idea of how knowing design patterns is akin to unlocking a toolbox of proven solutions, empowering you to tackle common software design challenges with confidence and efficiency. By incorporating these time-tested principles into your projects, you can elevate the quality, maintainability, and scalability of your software projects, personal or otherwise.
I really had fun sharing this with you, I hope you also had fun reading it. Thanks for reading the whole thing. Until the next time:
Keep Learning
Keep Growing
Subscribe to my newsletter
Read articles from Prince C. Ngumoha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Prince C. Ngumoha
Prince C. Ngumoha
I'm a Software Engineer (in the making) from Nigeria.