
TypeScript 4 Design Patterns and Best Practices
By :

With behavioral design patterns, you define abstractions that deal with relationships and the responsibilities between objects. You want to measure and manage how and when two or more objects can communicate with each other by message passing or direct references.
Often, you cannot merely obtain certain object references and call their methods, but you would like to use their functionality. Or you may have diverse ways to define the behavior of an object but you don't want to hardcode many switch statements or draft repetitive code.
The solution to these aforementioned problems is to define helper classes and interfaces that encapsulate this object's behavior and use them according to each occasion. By utilizing the behavioral patterns, you gain several benefits, including increased flexibility, low coupling, and reusability.
I will explain what I mean in greater detail as we look at these patterns, starting with the Chain of Responsibility...