Design Patterns: It's Like Baking a Cake

29 Nov 2023

What are design patterns?

Design patterns help pave the way for the future and development of an application. After you have finished developing an application or take a break from it, other developers may want to pick up where you left off and future improve it. This is where design patterns come into play. It allows developers to better understand your code making it easier for them to add any new features or fix bugs. Design patters are reusable solutions to problems that commonly occur. You can picture design patterns as a template that make the process faster, more organized, and less error-prone.

Just like baking a cake

I think every software engineer has been at this point of their career where they question and are confused on what design patterns are. I’m currently at that point right now. I’m still trying to make sense of it all, especially since there are so many different types of design patterns. But the easiest and simplest way that I see design patterns is like baking a cake.

Lets say you want to bake a cake but not quite sure how. You of course will follow a recipe, following each step and measurements exactly. The recipe is like a design pattern because it is the template that you are following. Instead of making the cake from the top of your head, not knowing what ingredients or measurements to use, following the recipe will make the process easier and less error-prone. By following the recipe, you are able to add any new ingredients or change the measurements to your liking. Just like adding new features to an application, you can add chocolate chips to your cake.

What design patterns have you used in your own code?

Before learning about what design patterns are, my team and I never really thought about design patterns or realized that we have been using them all along. We have used the singleton design pattern in our final project to create a global state for our application. We used it to store the user’s information when they log in and log out. This ensures that only one person is logged in at a time on a single device. This reduces the risk of having an unauthorized users accessing parts of the application where only admins allowed.

I’m sure that there are many other design patterns that we have used in our final project but because I’m fairly new to design patterns, I can’t pinpoint all of them as of right now. But as I learn more about the different design patterns, I will be able to identify them in our project and be able to implement them in any of my future projects.