PrepZone Logo
PrepZone

State and Template Method

Behaviour that changes with mode vs behaviour with fixed steps.

Read these first

Why this matters

  • State transitions — detailed pointwise breakdown in the section below.
  • Template hooks — detailed pointwise breakdown in the section below.
  • Vending machine states — detailed pointwise breakdown in the section below.
  • Export pipeline — detailed pointwise breakdown in the section below.
  • Patterns are forces and solutions — name the force before the pattern.
Idle
Moving
DoorOpen
Idle
State pattern keeps door logic separate from movement logic.

Overview

Behaviour that changes with mode vs behaviour with fixed steps. Study each section below in order — every list is interview-ready reference material.

State transitions

Points to cover

  • Definition — what State transitions 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

Template hooks

Points to cover

  • Definition — what Template hooks 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

Vending machine states

Points to cover

  • Definition — what Vending machine states 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

Export pipeline

Points to cover

  • Definition — what Export pipeline 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 "State transitions" on paper first, then in code
public final class StateAndTemplateExample {
    // 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. State transitions — review this slice before mock interviews.
  2. Template hooks — review this slice before mock interviews.
  3. Vending machine states — review this slice before mock interviews.
  4. Export pipeline — review this slice before mock interviews.

Test yourself

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