
TypeScript 4 Design Patterns and Best Practices
By :

The Command pattern deals with creating special request objects that can be passed as parameters to receiver objects. The main idea of this pattern is that you want to separate a request action from handling each request in a way that both the request and receiver objects are decoupled. For instance, say you create an object that contains all the information necessary to perform actions such as triggering notifications or emails. This object will contain information such as the receiver's email address, name, or title. The receiver merely knows how to process the commands and employs the appropriate handler depending on the type of command. This way, you promote the single-responsibility principle, which is part of the SOLID principles, as you separate the responsibilities of the classes that perform actions and the classes that create actions.
An analogy of this pattern is where you have a microwave with buttons that represent actions. When you press a...