Design Patterns Command Pattern - Design Patterns

What is Design Pattern Command Pattern?

Command pattern is a data determined propose pattern and falls under behavioural pattern group. A request is wrapped under an object as command and passed to invoker object. Invoker object looks for the correct object which can handle this command and passes the command to the matching object which executes the command.


We have formed an interface Order which is acting as a command. We have formed a Stock class which acts as a request. We have real command classes Buy Stock and Sell Stock implementing Order line which will do definite command processing. A class Broker is created which acts as an invoker entity. It can take and place preparation.

Broker entity uses command pattern to recognize which object will implement which command based on the type of command. CommandPatternDemo, our demo class, will use Broker class to express charge pattern.

Step 1

Create a command interface.

Step 2

Create a request class.

Step 3

Create concrete classes implementing the command interface.

Step 4

Create command invoker class.

Step 5

Use the Broker class to take and perform information.

Step 6

Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Design Patterns Topics