• Albert Bennett

Design Patterns: Command

Updated: Jul 12, 2021

As always here is the link to the GitHub repo :)

If this post has helped you feel free to like, comment and share.

In this post I'll be going through the Command pattern. How to use it and when to use it.

First of the Command pattern is useful for when you need to encapsulate a request as an object. It's great as an alternative to callbacks and tracking operations, queuing tasks, etc.

The diagram below shows how this pattern works:

The use case for our example is to manage incoming fast food orders in a restaurant.

Command (Waiter): This class calls methods of the Receiver (Chef).

Receiver (Chef): This class knows what to do and where the functionality is at.

Invoker (Guest): This class invokes the Command.

Here is how this pattern can be implemented using our sample use case.

I hope that this has helped you to understand the Command pattern. See you next time

( ͡° ͜ʖ ͡°)

<< More Design Patterns

4 views0 comments

Recent Posts

See All