Tuesday, August 20, 2024

Command design pattern

The command pattern is used to implement loose-coupling in a request-response model. In this pattern, the request is sent to the invoker and the invoker passes it to the encapsulated command object. The command object passes the request to the appropriate method of receiver to perform the specific action.

 Command in the Real World 

1.     One example of the command pattern being executed in the real world is the idea of a table order at a restaurant: the waiter takes the order, which is a command from the customer. This order is then queued for the kitchen staff.  The waiter tells the chef that a new order has come in, and the chef has enough information to cook the meal.

     2.     Task Scheduling: Tasks can be queued and executed at a later time, such as in job scheduling systems or command-line tools.

No comments:

Post a Comment