Learning Design Patterns

29 Apr 2021

Design patterns in programming are not taught to you, nor are you tested on it during a midterm or final, but it is rather a skill that is developed and learned through practice. They are best practices that are used by programmers in order to efficiently work on a task or problem. Over the course of one’s computer science education and career, upon encountering a task, it is almost second nature to know how to begin the problem. First, we must analyze the problem and create an algorithm. The skill to be able to stop and think and not start coding randomly is also learned through much trial and error. Then, we can begin implementing design patterns into our process. After developing an algorithm for a potential solution to our task, we may already have an idea on how we can get started. Whether it be assigning objects or creating methods to deal with the problem part-by-part, this is essentially implementing a design pattern.

Throughout my experience in computer science, I have discovered many different design patterns throughout the different languages I have programmed in. All of these design patterns can be classified into three categories: creational, structural, and behavioral design patterns. Creational design patterns deal with class or object creation patterns. I remember using singleton design patterns many times when I was first learning how to program in Java. By creating a single class which would create a single object, it was a very straightforward and easy way to learn about the relationship between objects and classes. Structural design patterns mostly involve how class inheritance effects object availability. I felt that it was very efficient to use a facade class when dealing with programming class inheritance in C++. Behavioral design patterns include how objects interact with each other. A very easy but efficient way to implement this would be to create a command design pattern. For instance, we could create a class that’s sole purpose would be to execute something. We would then create other classes that would implement that command class and use inheritance so that each object created would contain an execute command that could do what we want it to.

Depending on how much experience one has in programming, they would either not understand any of these design patterns, understand and actively implement them into their software engineering process, or even criticize some of them for their lack of efficiency in certain circumstances. Nonetheless, it is a crucial part of the common problem solving process that all programmers go through on their coding journey.