Member-only story
Design Patterns in a Coffee Shop: State, Strategy, Template, and Visitor
The Café Is Getting Smarter
Your coffee shop isn’t just about brewing drinks anymore. It’s about adapting to customer moods, applying different discount strategies, handling staff training routines, and even letting suppliers run audits on your menu.
That’s where these four design patterns come in:
- State — behavior changes based on situation
- Strategy — interchangeable algorithms for different goals
- Template — enforce a common process, with custom steps
- Visitor — add operations to objects without changing them
Let’s explore each through the lens of your café.
1. State Pattern — Behavior Changes with Context
The Analogy: Coffee Machine with Modes
Your coffee machine behaves differently depending on its mode:
- Idle: Do nothing.
- Brewing: Accept no other commands.
- Cleaning: Only…





