Imagine making a chocolate chip cookie from scratch. Without looking at a recipe, you could probably guess what kind of ingredients you’d need based on what you already know about a cookie. For example, I could probably guess that I’d need some flour, eggs, chocolate chips and butter. But how much do I need of each?
Without a recipe it’d be kind of hard to prepare this. I could throw all the ingredients together and conduct an experiment where I pray that each time I make a cookie, the outcome will be the cookie that I want, but of course while mixing up each try. Maybe in one trial I’ll pray on a carpet, the next I’ll pray on the toilet, each in hope that the next and the next will turn out successful. Several tries in, I’ll realize my “cookie” is not retaining it’s shape because I’m missing an ingredient I didn’t even know I needed (baking soda). Sounds kind of tedious and redundant though right? How do I fix what I’m doing wrong? How do I speed up the development process of making my chocolate chip cookie? I have the right ingredients but somehow my process is wrong and I don’t know where.
How do I produce the cookie that I want and be confident in replicating it? This is where design patterns come in. Design patterns in software engineering is a general solution that can speed up the development process with basically a pattern. (Eureka, God Bless whosevers soul, a recipe has been made!) Now we have a template that can be reused to solve reoccurring problems of different contexts. Going back to my post Familiarity in Formatting, it’s kind of the same concept of why we use coding structures; which is to follow a general outline and provide structure to our process. It minimizes the trials needed to run the experiment of creating the chocolate chip cookie I want!
Now I have a starting point. One of the first things we’ve learned is Classes and Objects and how to make a chocolate chip cookie. How do I take this information and create my own thing? A shortbread cookie, although different in taste and color, but same in the sense that it’s just another cookie, I can still take what I know from the process of making a chocolate chip cookie to make my shortbread one. Throughout my software engineering class, we’ve learned modules of different topics and set off to replicate them ourselves in a different setting. I can use these different design patterns in my code to provide a base and foundation to build off of. For example when I want to instantiate something, I can use a Prototype Design Pattern to build an instance over another instance. What do all cookies need? What is the process for each cookie?
Without Design Patterns, starting from scratch would be very tedious, we’d leave so much room for trials and errors and wounds from head banging against walls from frustration trying to figure out the right ratio to making a cookie. Use the design patterns and solve that issue! But use it as a launchpad to guide you into adjusting the perfect cookie for YOUR tastes.