© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
V. SarcarJava Design Patternshttps://doi.org/10.1007/978-1-4842-7971-7_19

19. Command Pattern

Vaskaran Sarcar1  
Garia, Kolkata, India

This chapter covers the Command pattern.

GoF Definition

It encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.


Using this pattern, you encapsulate a method invocation process. Here an object can invoke an operation through some crystalized method, and it does not worry about how to perform the intended operation. This pattern is often used in a multithreaded environment. It’s one of those patterns that is normally ...

Get Java Design Patterns: A Hands-On Experience with Real-World Examples now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.