Recipes: Design Patterns And Principles
Design patterns are solutions to recurring problems guidelines on how to tackle certain problems.
Last updated
Design patterns are solutions to recurring problems guidelines on how to tackle certain problems.
Last updated
While having a vibe of a mad genius might be tempting, reinventing the wheel is usually not the best way to approach designing your software. The chances are that somebody already had the same problem as you and solved it in a smart way. Such best practices, when formalized, are called design patterns.
We can treat design patterns as proven solutions that many developers tested in various real-life situations. They aim to support software designers in solving common problems in a readable and predictable way. If we base our application on proven patterns, we can worry less about the overall structure because they tend to encourage us to write our code in an organized way.
Looking into an already existing codebase that incorporates one of the design patterns might be easier than trying to understand an unfamiliar approach. They also act as a bridge between other developers and us. Using well-known strategies makes communication faster and easier.
The design patterns don’t act as exact solutions. They provide us with a scheme that we can adapt to suit our own needs. The fact that the patterns are not tied to a specific problem makes them very reusable. They are not associated with a particular programming language, but JavaScript has design patterns that are more popular than others.
You probably already use some of them. Common JavaScript solutions tend to have design patterns that feel adequate when implemented. React often incorporates the Higher-Order component pattern and the flux architecture. Angular applications seem to work well when implementing the observer design pattern.
Design patterns are not a silver bullet to all your problems.
Do not try to force them bad things are supposed to happen, if done so. Keep in mind that design patterns are solutions to problems, not solutions finding problems so don't overthink.
If used in a correct place in a correct manner, they can prove to be a savior or else they can result in a horrible mess of a code.
Creational
Structural
Behavioral
In plain words
Creational patterns are focused towards how to instantiate an object or group of related objects.
Wikipedia says
In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation.
Abstract Factory
Prototype
In plain words
Structural patterns are mostly concerned with object composition or in other words how the entities can use each other. Or yet another explanation would be, they help in answering "How to build a software component?"
Wikipedia says
In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities.
In plain words
It is concerned with assignment of responsibilities between the objects. What makes them different from structural patterns is they don't just specify the structure but also outline the patterns for message passing/communication between them. Or in other words, they assist in answering "How to run a behavior in software component?"
Wikipedia says
In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.