CS FundamentalsHardProduct-company placement

A text editor needs multi-level undo and redo, and also wants to queue and log user actions such as 'insert text' or 'delete line'. Which pattern is the natural fit?

  1. A. Observer
  2. B. Memento only
  3. C. Command, with each action an object that knows how to execute and undo itself
  4. D. Mediator

Correct answer: C. Command, with each action an object that knows how to execute and undo itself

Command turns each request into an object that can be stored on undo/redo stacks, queued or logged. Memento can help save state for undo but does not by itself model queued, loggable actions.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic