Command
Another design pattern with huge importance in Node.js is Command. In its most generic definition, we can consider a command any object that encapsulates all the information necessary to perform an action at a later time. So, instead of invoking a method or a function directly, we create an object representing the intention to perform such an invocation. It will then be the responsibility of another component to materialize the intent, transforming it into an actual action. Traditionally, this pattern is built around four major components, as shown in Figure 9.6:
Figure 9.6: The components of the Command pattern
The typical configuration of the Command pattern can be described as follows:
- Command is the object encapsulating the information necessary to invoke a method or function.
- Client is the component that creates the command and provides it to the invoker.
- Invoker is the component responsible for executing the command...