⚙️ ISABELLE RUNE DIFFICULTY: Adept Behavioral

The Observer

Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified automatically.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Observer
ARCANUM SCHOOL: Divination // Perception
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ISABELLE PATTERN //
theory Observer
  imports Main
begin

type_synonym observer = "string \<Rightarrow> string list"

record subject =
  observers :: "observer list"
  state :: string

definition notify_all :: "subject \<Rightarrow> string list list" where
  "notify_all sub = map (\<lambda>obs. obs (state sub)) (observers sub)"

end
Runic Tags: #isabelle #hol #divination #design-patterns