Coding with Design Patterns

29 Apr 2021

Learning about Design Patterns

PatternLanguage Computer Science is one of the subjects that many people with no experience in the field consider it very difficult to get into. Luckily, design patterns exists as a way to help newbies become introduced in a user-friendly way. First of all, design patterns is basically a template that can be used in many different situations. Through trial and error of many different solutions, one solution becomes the general answer to a problem that occurs over and over again for the community. Which eventually becomes the template for new users and veterans to utilize when coding. It was first introduced in a book called “A Pattern Language”, written by Christopher Alexander in 1977. And then later improved upon in a book called “Gang of Four” in 1994.

Examples

For example, one of the design patterns mention above includes the singleton. Singleton acts as a way to provide a global variable in Object Oriented languages that does not support global variables. Sometimes in languages such as Java, you’ll find yourself needing to implement a global variable to be used in multiple classes. The singleton design pattern allows users to easily implement variables with a global state. Another example would be the Observer design pattern. Basically, the observer design pattern allows users to create code that only functions if certain events occurs (event handlers).

Personal Experiences using Design Patterns

Ever since I became a computer science major, I always found myself utilizing design patterns created by the community to help with the development of my coding. In ICS 211, one of the assignments (pizza-bakery-application) required us to use a global variable in Java, which were I was introduced to the Singleton Pattern and implemented it into my own code. Recently, in ICS 314, given the task of developing a website application from scratch. I was able to use the meteor-react-template as a guide to this assignment as it saves you time and effort from writing the foundation of the website. Personally, reading code is always much simpler than writing code. So using the template as the foudation of my website application, I can easily find and change the necessary components to make the website my own.

Conclusion

Overall, design patterns allows newbies to gain the experience of writing code to solutions to a a commonly occuring problem in software design. Design patterns is extremely useful in helping users get over the steep learning curve that is Computer Science.