← Design Patterns learning path
Design Patterns · Module 7 of 10

Command, State and Template Method

More behavioural patterns.

📖 Key ideas

  1. Command wraps a request as an object: supports undo, queues, logging.
  2. State changes an object's behaviour when its state changes (order: placed → shipped → delivered).
  3. Template Method defines an algorithm skeleton; subclasses fill steps.
  4. Iterator gives sequential access without exposing structure.
  5. Chain of Responsibility passes a request along handlers.
💡 Real-life example: Template Method is a fill-in-the-blanks exam paper: structure fixed, answers vary by student.
CommandRequest as an object
StateBehaviour changes with state
Template MethodAlgorithm skeleton with overridable steps
Chain of ResponsibilityRequest passed along handlers