FlowDiagram
UML: sequence, class & stateMermaid

Observer and strategy design patterns class diagram template

Shows the Gang of Four observer and strategy patterns together: a subject notifying observers and a context delegating to interchangeable strategies; used to teach design patterns. This class diagram has 8 classes and 7 relationships. It imports as editable UML class boxes with inheritance, composition and association arrows.

Open in the editor →
  • Free — no account, no trial, no watermark
  • Fully editable shapes and connectors, not a screenshot
  • Export PNG, SVG or PDF, or share it as a link
  • Private: the diagram never leaves your browser

Classes in this class diagram

  • Subject — 4 members
  • Observer — 2 members
  • PriceTicker — 3 members
  • ChartView — 1 member
  • AlertService — 2 members
  • PricingStrategy — 2 members
  • DiscountStrategy — 2 members
  • SurgeStrategy — 2 members

How to use this class diagram template

  1. Click Open in the editor. The class diagram opens on a new page in FlowDiagram — nothing is uploaded and there is no sign-up.
  2. Rename, add or delete shapes and drag them where you want; connectors stay attached as things move.
  3. Drop in vendor logos from the library — 1,160 of them, including every AWS, Azure and Google Cloud service icon — or restyle it with the colour and theme controls.
  4. Prefer text? Edit the Mermaid source below and paste it in through ☰ → Import diagram (see the Mermaid editor); it imports as an editable diagram.
  5. Export to PNG, SVG or PDF, or press Ctrl+L for a link that carries the whole diagram.

Mermaid source

The whole template is the text below. Paste it into FlowDiagram, keep it in Git next to the code it describes, or hand it to an AI assistant to extend.

classDiagram
  class Subject {
    <<interface>>
    +attach(Observer o) void
    +detach(Observer o) void
    +notify() void
  }
  class Observer {
    <<interface>>
    +update(Subject s) void
  }
  class PriceTicker {
    -float price
    +setPrice(float p) void
    +notify() void
  }
  class ChartView {
    +update(Subject s) void
  }
  class AlertService {
    +float threshold
    +update(Subject s) void
  }
  class PricingStrategy {
    <<interface>>
    +quote(float base) float
  }
  class DiscountStrategy {
    +float percent
    +quote(float base) float
  }
  class SurgeStrategy {
    +float multiplier
    +quote(float base) float
  }
  Subject <|.. PriceTicker
  Observer <|.. ChartView
  Observer <|.. AlertService
  Subject o-- Observer
  PricingStrategy <|.. DiscountStrategy
  PricingStrategy <|.. SurgeStrategy
  PriceTicker --> PricingStrategy : uses

Related: Mermaid editor · All uml: sequence, class & state templates · All 521 templates