Which statement describes the Command pattern?

Get ready for your Object‑Oriented Programming Test. Use flashcards and multiple-choice questions. Each question includes hints and explanations. Prepare for your exam today!

Multiple Choice

Which statement describes the Command pattern?

Explanation:
The Command pattern is about turning a request into a stand-alone object that can be passed around, stored, or undone. This object usually provides an execute method, and often an undo method, which allows the same command to be invoked by different parts of a system without those parts needing to know how the action is carried out. Because the sender of the command only interacts with the command object and not with the receiver, the two are decoupled, making it easy to queue commands, log them, or implement undo/redo functionality. The statement highlighting encapsulating a request as an object with execute and undo, while decoupling sender and receiver, captures this idea precisely. The other descriptions describe different ideas—direct method calls imply tight coupling, data persistence focuses on storage, and lazy initialization targets performance optimization—not the command pattern.

The Command pattern is about turning a request into a stand-alone object that can be passed around, stored, or undone. This object usually provides an execute method, and often an undo method, which allows the same command to be invoked by different parts of a system without those parts needing to know how the action is carried out. Because the sender of the command only interacts with the command object and not with the receiver, the two are decoupled, making it easy to queue commands, log them, or implement undo/redo functionality. The statement highlighting encapsulating a request as an object with execute and undo, while decoupling sender and receiver, captures this idea precisely. The other descriptions describe different ideas—direct method calls imply tight coupling, data persistence focuses on storage, and lazy initialization targets performance optimization—not the command pattern.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy