Hi everyone! Today I will we writing about design patterns in computer science. This is a topic that I initially undervalued and did not bother to learn in depth. However, a recent project I worked on has changed that perspective. I am currently on my second MECOP internship, and my primary project has been algorithmic in nature. The need for object oriented programming becomes apparent when working with complex data models. The website GeeksforGeeks provides many articles that can help you become adjusted to these ideas. Here are a few of the popular design patterns in computer science:
Singleton
The singleton design pattern is applicable when you have a class that only needs to be invoked to make one object. There are scenarios where it is important that only one instance of a class controls the entire program. Testing can be troublesome with singletons because the global nature of them is not conducive to unit testing
Factory Method
Unlike the singleton design pattern, the factory method involves the creation of many objects. The factory method creates objects in the way its name describes. It has a method who’s purpose is to create and return objects. Importantly, the background machinations are black boxed to whatever is receiving the returned objects.
Observer
The primary concept for this design pattern is to have one object modify the states of many dependent objects. A real world example that this makes me think of is the children’s game Simon Says. In this game the leader, Simon, dictates an action that the other participants must follow. This is the same concept as the observer design pattern (but hopefully your data model is more accurate).
Why are design patterns important?
As the common adage goes, there is no need to reinvent the wheel. Why try to create your own design patter when someone else has already done it? Furthermore, the thee design patterns I listed above have been thoroughly tested. When used correctly, each one can offer best practices . This will make your code robust and efficient. I hope you learned something about design patters today. I will be making more of an effort to adhere to design patterns and I hope you do too!