Sitemap
Minh Le Duc

Minh Le Duc

Just Another Dev Guy

Member-only story

Design Patterns in a Coffee Shop: State, Strategy, Template, and Visitor

The Café Is Getting Smarter

4 min readJul 29, 2025

--

Press enter or click to view image in full size

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

Image from [1]

Your coffee machine behaves differently depending on its mode:

  • Idle: Do nothing.
  • Brewing: Accept no other commands.
  • Cleaning: Only…

--

--