PrepZone Logo
PrepZone

Command and Undo

Encapsulate requests as objects for queues, logging, and undo stacks.

Read these first

Why this matters

  • Command interface — detailed pointwise breakdown in the section below.
  • Invoker — detailed pointwise breakdown in the section below.
  • Undo stack — detailed pointwise breakdown in the section below.
  • CampusOS editor — detailed pointwise breakdown in the section below.
  • Patterns are forces and solutions — name the force before the pattern.
Invoker
Commandexecute() / undo()
Receiver
Encapsulate requests as objects — enables undo, queue, and logging.

Overview

Encapsulate requests as objects for queues, logging, and undo stacks. Study each section below in order — every list is interview-ready reference material.

Command interface

Points to cover

  • Definition — what Command interface means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design

Invoker

Points to cover

  • Definition — what Invoker means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design

Undo stack

Points to cover

  • Definition — what Undo stack means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design

CampusOS editor

Points to cover

  • Definition — what CampusOS editor means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design
Java
// CampusOS — apply "Command interface" on paper first, then in code
public final class CommandAndUndoExample {
    // 1. Name entities from the problem statement
    // 2. Draw relationships before writing methods
    // 3. Introduce patterns only when a force appears
}

Quick recall

Everything you need if you only revisit this box.

  1. Command interface — review this slice before mock interviews.
  2. Invoker — review this slice before mock interviews.
  3. Undo stack — review this slice before mock interviews.
  4. CampusOS editor — review this slice before mock interviews.

Test yourself

Answer these before moving on — recall is what makes it stick.