Skip to main content

Command Pattern

Learn Command Pattern (Behavioral Patterns, Design Patterns in Java) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Command Pattern turns a request into a standalone object containing everything needed to perform an action (or undo it) - decoupling the object that invokes an operation from the object that knows how to perform it. Real-Life Example: A TV remote control - each button is a Command object that knows what device action to trigger Restaurant order slips - a waiter writes a command that the kitchen executes later, independently Undo/redo functionality in text editors Why do we need Command? To decouple the sender (the button/invoker) from the receiver (the object that does the actual work) To...

More lessons in Behavioral Patterns