Just hearing the name design pattern can make you think it's either gimmicky or something extremely complicated.
The thing is neither. It is a very familiar name in Object Oriented Programming (OOP). We think of everything in OOP as objects. We will program like this, and new things will come up all at once - and we will solve them in a new way with our heads, it's not like that.
Many times the same kind of problem comes forward. Some smart people have deconstructed them and come up with very good solutions. These kinds of common problems can be solved very easily, very nicely, if you keep them in mind; There is no need to sweat or waste time as the solution does not have to be repeated. An example will make it clear.
Let's say I have a Manager class. I want my programming world to have only one manager in that software and he will do all the management alone. I can't create more than one manager even if another programmer or I want to.
The solution is very simple. I will always send a manager as a parameter wherever a manager is needed. And I will create a manager at the very beginning of the program - whether anyone needs it or not. I will also send a note to the rest of my team asking them to use my manager instead of making a new manager.
This is actually very messy and a very bad solution. Why or how we will send a manager as a parameter, why or I will memorize and make others, "There is no more than one manager, there will not be more than one manager, so the project manager will come and hit the house on the head" - such questions come to mind.
Another type of it can be a configuration class in place of the manager. It will contain some very important information, like how many other classes will work, dance, sing, etc.
If I want to change the nature of all the classes, I change an object of that configuration class. And the rest of the objects recognize that one configuration object - they will change their nature after seeing it. Now if the rest of the objects each recognize a different configuration object, then great danger! Static class can be a solution in this case, but it is not always used.
Top comments (0)