The command pattern is a data-driven design pattern that belongs to the behavior pattern category. The request is wrapped as a command under an object and passed to the caller object. The caller object looks for the appropriate object that can handle this command, and passes the command to the appropriate object that executes the command.
Implementing an instance
In this example, an interface is created as a command- Order and a class is created as a Stock request. There are specific command classes BuyStock and SellStock implementation Order interfaces that will do the actual command processing. A class is created Broker as the caller object. It can receive and place orders.
BrokerObject uses command mode to identify which object and which command to execute according to the command type. CommandPatternDemoThis is a demo entry class that will use the Broker class to demonstrate the command pattern.
The implementation instance structure of the command pattern is as shown in-
Click on the link to view the details
Java Command mode ~