# dotnet-labs/headfirstdesignpattern architecture

> Architecture diagram of the GitHub repository dotnet-labs/headfirstdesignpattern, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dotnet-labs/headfirstdesignpattern
- Repository: https://github.com/dotnet-labs/headfirstdesignpattern

## Overview

This repository is a collection of runnable Head First design-pattern exercises, not one integrated application. Each example program demonstrates a pattern through a small domain scenario, such as ordering pizza, printing menus, operating a gumball machine, or simulating ducks. The graph groups examples by pattern role and shows only workflows supported by the sampled programs or the README; several implementation details are represented by their exact enclosing directories because their source was not sampled.

Main entry points: [`DecoratorPattern/Program.cs`](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/DecoratorPattern/Program.cs) (Coffee demo), [`ObserverPattern/Program.cs`](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/ObserverPattern/Program.cs) (Weather demo), [`IteratorPattern/Program.cs`](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/IteratorPattern/Program.cs) (Menu iterator demo), [`FactoryPattern/PizzaStore`](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/FactoryPattern/PizzaStore) (Pizza stores)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_behavioral["Behavioral Patterns"]
  node_strategy_entry["Duck demo<br/>[Program.cs]"]
  node_duck_behaviors["Duck behaviors"]
  node_observer_entry["Weather demo<br/>[Program.cs]"]
  node_weather_data["Weather subject<br/>[Weatherdata.cs]"]
  node_weather_displays["Weather displays"]
  node_command_entry["Remote demo<br/>[Program.cs]"]
  node_remote_control["Remote controls"]
  node_commands["Device commands"]
  node_devices["Controlled devices"]
  node_iterator_entry["Menu iterator demo<br/>[Program.cs]"]
  node_menus_iterators["Menus and iterators"]
  node_iterator_waitress["Menu printer<br/>[Waitress.cs]"]
  node_state_entry["Gumball demo<br/>[Program.cs]"]
  node_gumball_machine["Gumball machine<br/>[GumballMachine.cs]"]
  node_machine_states["Machine states"]
end

subgraph group_creation["Creational Patterns"]
  node_factory_entry["Pizza demo<br/>[Program.cs]"]
  node_pizza_stores["Pizza stores"]
  node_pizza_products["Pizza products"]
  node_ingredient_factories["Ingredient factories"]
  node_singleton_entry["Boiler demo<br/>[Program.cs]"]
  node_chocolate_boiler["Chocolate boiler<br/>[ChocolateBoiler.cs]"]
end

subgraph group_structure["Structural Patterns"]
  node_decorator_entry["Coffee demo<br/>[Program.cs]"]
  node_coffee_components["Coffee beverages"]
  node_coffee_decorators["Coffee add-ons"]
  node_coffee_sizes["Size decorators"]
  node_composite_entry["Menu composition demo<br/>[Program.cs]"]
  node_menu_components["Menu hierarchy"]
  node_composite_waitress["Menu printer<br/>[Waitress.cs]"]
  node_proxy_example["Proxy examples"]
end

subgraph group_compound["Compound Example"]
  node_compound_entry["Duck simulator<br/>[Program.cs]"]
  node_duck_simulator["Simulation scenarios<br/>[DuckSimulator.cs]"]
  node_duck_factory["Duck factories"]
  node_duck_flock["Duck flocks<br/>[Flock.cs]"]
end

node_engineer(("Example runner"))

node_engineer -->|"runs demo"| node_strategy_entry
node_strategy_entry -->|"sets behavior"| node_duck_behaviors
node_engineer -->|"runs demo"| node_observer_entry
node_observer_entry -->|"creates subject"| node_weather_data
node_observer_entry -->|"creates displays"| node_weather_displays
node_weather_data -.->|"notifies"| node_weather_displays
node_engineer -->|"runs demo"| node_command_entry
node_command_entry -->|"runs tests"| node_remote_control
node_remote_control -.->|"dispatches"| node_commands
node_commands -.->|"operates"| node_devices
node_engineer -->|"runs demo"| node_iterator_entry
node_iterator_entry -->|"creates menus"| node_menus_iterators
node_iterator_entry -->|"prints menu"| node_iterator_waitress
node_engineer -->|"runs demo"| node_state_entry
node_state_entry -->|"operates"| node_gumball_machine
node_gumball_machine -->|"delegates actions"| node_machine_states
node_engineer -->|"runs demo"| node_factory_entry
node_factory_entry -->|"orders pizza"| node_pizza_stores
node_pizza_stores -.->|"creates"| node_pizza_products
node_pizza_stores -.->|"uses"| node_ingredient_factories
node_engineer -->|"runs demo"| node_singleton_entry
node_singleton_entry -->|"gets instance"| node_chocolate_boiler
node_engineer -->|"runs demo"| node_decorator_entry
node_decorator_entry -->|"creates beverage"| node_coffee_components
node_decorator_entry -->|"wraps beverage"| node_coffee_decorators
node_decorator_entry -->|"adds size"| node_coffee_sizes
node_engineer -->|"runs demo"| node_composite_entry
node_composite_entry -->|"builds hierarchy"| node_menu_components
node_composite_entry -->|"prints menu"| node_composite_waitress
node_engineer -->|"explores pattern"| node_proxy_example
node_engineer -->|"runs demo"| node_compound_entry
node_compound_entry -->|"runs scenarios"| node_duck_simulator
node_duck_simulator -.->|"uses factory"| node_duck_factory
node_duck_simulator -.->|"simulates flocks"| node_duck_flock

click node_strategy_entry "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/StrategyPattern/Program.cs"
click node_duck_behaviors "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/StrategyPattern/Duck"
click node_observer_entry "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/ObserverPattern/Program.cs"
click node_weather_data "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/ObserverPattern/Weatherdata.cs"
click node_weather_displays "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/ObserverPattern"
click node_command_entry "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CommandPattern/Program.cs"
click node_remote_control "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/CommandPattern/RemoteControl"
click node_commands "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/CommandPattern/RemoteControl/Commands"
click node_devices "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/CommandPattern/RemoteControl/Commands"
click node_iterator_entry "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/IteratorPattern/Program.cs"
click node_menus_iterators "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/IteratorPattern/Menu"
click node_iterator_waitress "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/IteratorPattern/Waitress/Waitress.cs"
click node_state_entry "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/StatePattern/Program.cs"
click node_gumball_machine "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/StatePattern/GumballMachines/GumballMachine.cs"
click node_machine_states "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/StatePattern/States"
click node_factory_entry "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/FactoryPattern/Program.cs"
click node_pizza_stores "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/FactoryPattern/PizzaStore"
click node_pizza_products "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/FactoryPattern/PizzaProduct"
click node_ingredient_factories "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/FactoryPattern/PizzaIngredient"
click node_singleton_entry "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/SingletonPattern/Program.cs"
click node_chocolate_boiler "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/SingletonPattern/ChocolateBoiler.cs"
click node_decorator_entry "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/DecoratorPattern/Program.cs"
click node_coffee_components "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/DecoratorPattern/Coffee/Beverages"
click node_coffee_decorators "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/DecoratorPattern/Coffee/Condiments"
click node_coffee_sizes "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/DecoratorPattern/Coffee/Sizes"
click node_composite_entry "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CompositePattern/Program.cs"
click node_menu_components "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/CompositePattern/MenuComponent"
click node_composite_waitress "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CompositePattern/Waitress/Waitress.cs"
click node_proxy_example "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/ProxyPattern"
click node_compound_entry "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CompoundPattern/Program.cs"
click node_duck_simulator "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CompoundPattern/DuckSimulator.cs"
click node_duck_factory "https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/CompoundPattern/DuckFactory"
click node_duck_flock "https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CompoundPattern/Flock/Flock.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_strategy_entry,node_duck_behaviors,node_observer_entry,node_weather_data,node_weather_displays,node_command_entry,node_remote_control,node_commands,node_devices,node_iterator_entry,node_menus_iterators,node_iterator_waitress,node_state_entry,node_gumball_machine,node_machine_states toneBlue
class node_factory_entry,node_pizza_stores,node_pizza_products,node_ingredient_factories,node_singleton_entry,node_chocolate_boiler toneAmber
class node_decorator_entry,node_coffee_components,node_coffee_decorators,node_coffee_sizes,node_composite_entry,node_menu_components,node_composite_waitress,node_proxy_example toneMint
class node_compound_entry,node_duck_simulator,node_duck_factory,node_duck_flock toneRose
class node_engineer toneIndigo
```

## Components

### Behavioral Patterns

- [Duck demo](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/StrategyPattern/Program.cs): `StrategyPattern/Program.cs`
- [Duck behaviors](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/StrategyPattern/Duck): `StrategyPattern/Duck`
- [Weather demo](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/ObserverPattern/Program.cs): `ObserverPattern/Program.cs`
- [Weather subject](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/ObserverPattern/Weatherdata.cs): `ObserverPattern/Weatherdata.cs`
- [Weather displays](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/ObserverPattern): `ObserverPattern`
- [Remote demo](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CommandPattern/Program.cs): `CommandPattern/Program.cs`
- [Remote controls](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/CommandPattern/RemoteControl): `CommandPattern/RemoteControl`
- [Device commands](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/CommandPattern/RemoteControl/Commands): `CommandPattern/RemoteControl/Commands`
- [Controlled devices](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/CommandPattern/RemoteControl/Commands): `CommandPattern/RemoteControl/Commands`
- [Menu iterator demo](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/IteratorPattern/Program.cs): `IteratorPattern/Program.cs`
- [Menus and iterators](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/IteratorPattern/Menu): `IteratorPattern/Menu`
- [Menu printer](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/IteratorPattern/Waitress/Waitress.cs): `IteratorPattern/Waitress/Waitress.cs`
- [Gumball demo](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/StatePattern/Program.cs): `StatePattern/Program.cs`
- [Gumball machine](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/StatePattern/GumballMachines/GumballMachine.cs): `StatePattern/GumballMachines/GumballMachine.cs`
- [Machine states](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/StatePattern/States): `StatePattern/States`

### Creational Patterns

- [Pizza demo](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/FactoryPattern/Program.cs): `FactoryPattern/Program.cs`
- [Pizza stores](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/FactoryPattern/PizzaStore): `FactoryPattern/PizzaStore`
- [Pizza products](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/FactoryPattern/PizzaProduct): `FactoryPattern/PizzaProduct`
- [Ingredient factories](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/FactoryPattern/PizzaIngredient): `FactoryPattern/PizzaIngredient`
- [Boiler demo](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/SingletonPattern/Program.cs): `SingletonPattern/Program.cs`
- [Chocolate boiler](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/SingletonPattern/ChocolateBoiler.cs): `SingletonPattern/ChocolateBoiler.cs`

### Structural Patterns

- [Coffee demo](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/DecoratorPattern/Program.cs): `DecoratorPattern/Program.cs`
- [Coffee beverages](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/DecoratorPattern/Coffee/Beverages): `DecoratorPattern/Coffee/Beverages`
- [Coffee add-ons](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/DecoratorPattern/Coffee/Condiments): `DecoratorPattern/Coffee/Condiments`
- [Size decorators](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/DecoratorPattern/Coffee/Sizes): `DecoratorPattern/Coffee/Sizes`
- [Menu composition demo](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CompositePattern/Program.cs): `CompositePattern/Program.cs`
- [Menu hierarchy](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/CompositePattern/MenuComponent): `CompositePattern/MenuComponent`
- [Menu printer](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CompositePattern/Waitress/Waitress.cs): `CompositePattern/Waitress/Waitress.cs`
- [Proxy examples](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/ProxyPattern): `ProxyPattern`

### Compound Example

- [Duck simulator](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CompoundPattern/Program.cs): `CompoundPattern/Program.cs`
- [Simulation scenarios](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CompoundPattern/DuckSimulator.cs): `CompoundPattern/DuckSimulator.cs`
- [Duck factories](https://github.com/dotnet-labs/headfirstdesignpattern/tree/master/CompoundPattern/DuckFactory): `CompoundPattern/DuckFactory`
- [Duck flocks](https://github.com/dotnet-labs/headfirstdesignpattern/blob/master/CompoundPattern/Flock/Flock.cs): `CompoundPattern/Flock/Flock.cs`

### Other components

- **Example runner**

## Connections

- Example runner → Duck demo: runs demo
- Duck demo → Duck behaviors: sets behavior
- Example runner → Weather demo: runs demo
- Weather demo → Weather subject: creates subject
- Weather demo → Weather displays: creates displays
- Weather subject → Weather displays: notifies
- Example runner → Remote demo: runs demo
- Remote demo → Remote controls: runs tests
- Remote controls → Device commands: dispatches
- Device commands → Controlled devices: operates
- Example runner → Menu iterator demo: runs demo
- Menu iterator demo → Menus and iterators: creates menus
- Menu iterator demo → Menu printer: prints menu
- Example runner → Gumball demo: runs demo
- Gumball demo → Gumball machine: operates
- Gumball machine → Machine states: delegates actions
- Example runner → Pizza demo: runs demo
- Pizza demo → Pizza stores: orders pizza
- Pizza stores → Pizza products: creates
- Pizza stores → Ingredient factories: uses
- Example runner → Boiler demo: runs demo
- Boiler demo → Chocolate boiler: gets instance
- Example runner → Coffee demo: runs demo
- Coffee demo → Coffee beverages: creates beverage
- Coffee demo → Coffee add-ons: wraps beverage
- Coffee demo → Size decorators: adds size
- Example runner → Menu composition demo: runs demo
- Menu composition demo → Menu hierarchy: builds hierarchy
- Menu composition demo → Menu printer: prints menu
- Example runner → Proxy examples: explores pattern
- Example runner → Duck simulator: runs demo
- Duck simulator → Simulation scenarios: runs scenarios
- Simulation scenarios → Duck factories: uses factory
- Simulation scenarios → Duck flocks: simulates flocks
