The Blueprints to Coding

30 Apr 2020

As amateur programmers, we usually write code with the intent for the program to work and function as needed. What we don’t realize is that after a while, our code becomes structured to a specific design pattern experts in the past have perfected through trial and error. This is what I’ve come to learn as design patterns and could be tied with day-to-day situations like finding the best roof design for different states. Different types of roofs were probably tried and tested before coming to terms for the the most applicable roof design for each state. Based on weather conditions, the butterfly roof was the most suited for snowy regions like Alaska. Similarly, bridges have the same concept, but with serious or deadly consequences when using the wrong type of design. There are numerous types of bridges, each of them serving a different purpose. Civil engineers have studied these bridges carefully and have applied the designs accordingly to be the most practical, safe, and cost-effective. As we create things, we should to have a thought process of how we want to structure things. That is why design patterns are there to help guide us and reason about the way we code things. These patterns are like the blueprints to our code. In most cases, we do not want to tackle the problem blindly and hope that whatever solution we come up with will suffice.

What are design patterns in Software engineering?

In software engineering, design patterns are a way of structuring our code to keep consistency. Experienced software engineers have come up with these patterns as solutions to common problems for later developers to use. Instead of re deriving the problem, we can learn from these developers to apply these designs into our own code once we have understood the purpose of these designs. They are to make things more efficient so that we could reuse the code in the future. In group projects, they serve to better organize the issues and format the code in a cohesive manner so it is easier for all the collaborators to understand. Each design has its own advantages and disadvantages. Some advantages and disadvantages are the complexity of implementing and understanding the designs, but with learning comes challenges. If we learn the complex designs that have more advantages than going the easier route, it will be beneficial to our code in the long run once we get the hang of the pattern.

Inherent Design Patterns in our projects

From the several web pages we’ve created in class using meteor and MongoDB, I have learned that a pattern we’ve used in this process of development is the Model-View-Controller (MVC) pattern. It is no surprise as this is the most commonly used pattern in web development as we are separating the state of system from the way it is presented to user. In the digits and Bowfolios websites, we have the MongoDB collection serving as the model, where we have all our collection classes such as the contacts, profiles, or interests. For the View in our digits website, we have React as the rendering system for the website. An example of a Controller is the React Router to navigate around the pages. Another pattern we use is the Singleton, where we have the variable, Contacts, as a singleton instance for the Contacts collection which has access to the MongoDB collection. This is to be exported so that it could be used by other classes upon import of Contacts collection. Additionally, we have used the Publisher-Subscriber design pattern where we publish collections so that others can subscribe to in order to obtain information for that collection. The over arching theme of design patterns is to save time, and to write coherent and purposeful code not only for ourselves, but for everyone else in group projects.