B2.4 · Archetypes and Composition — manuscript chapter 2.4
An archetype is data.
The part preface promised the Looking Glass move on the BEAM; this chapter performs it. An archetype is an entity under a newly registered ARC namespace whose value is a property bundle, extending at most one parent — and an instrument is a reference plus overrides, composed into a view at read time by a pure fold. No behaviour modules, no protocol dispatch on kind, no hierarchy of code anywhere in the design.
The chapter is content/bcs2.4.md; the rung behind it is
bcs_rung_2_4_check.exs, and its committed record closes PASS 5/5. Composition
order, amplification, shape guards, ordinary rows, the read cost across three lanes — each gated on
stage.
Composition over class inheritance
content/bcs2.4.md · WhyInstrument taxonomies are where class hierarchies go to grow teeth: equity, future, option, each sharing margin and settlement machinery, each diverging somewhere — and twenty years of inherited game-engine wisdom says the subclass tree ends in tears. West's component turn was the industry-scale retreat from exactly this shape, and the Gang of Four had stated the principle a decade earlier: favor composition over class inheritance, a judgment Gamma stood by — “I still think it's true even after ten years” — because the base-subclass coupling is implicit and brittle. BCS gives the principle its data-only form, so the trading desk's “all index futures now mark daily” is an edit to one entity, not a redeploy of a class.
The shared semantics are a row
An archetype bundle lives in the :archetypes store under ARC; it may
carry :extends naming one parent — gated by A1 and A3.
The kind is a reference
An instrument row carries archetype: — the reference — and answers a definition edit
at next read, with no fan-out write — gated by A2.
The specialization is a map
overrides: carries the deltas; overrides carry facts, archetypes carry semantics —
the review line the Decisions section states.
The registry grows by one
ARC, archetype definitions, platform scope — recorded as a decision because
registration is the governance act Chapter 1.2 said it is.
The proof
content/bcs2.4.md · quoting bcs_rung_2_4_check.outThe full committed transcript, verbatim — boot, then A1 through A5:
boot: the registry grows by one -- ARC, archetype definitions as rows A1 order ok -- composition order proven: tick 0.25 from the instrument, settlement :daily_mark from the archetype, margin true from the base A2 amplify ok -- one definition edited, a thousand instruments follow: multiplier 100 at next read; an instrument row is 18 words, its composed view 14 A3 guard ok -- the diamond is unrepresentable (one :extends) and the cycle is refused: {:error, :cycle}; depth capped at 8: {:error, :depth} A4 rows ok -- archetypes are rows: an AST name refused with {:error, :namespace}; ARC pages newest-first like any property A5 cost ok -- read-time composition over a depth-2 chain: store-lane 5442 ns/op vs snapshot-lane 1048 ns/op; a bare row get is 2653 ns/op PASS 5/5
The resolver lives at runtimes/elixir/lib/echo_data/bcs/archetypes.ex; it is
pure by construction — it takes a fetch function, so the same walk runs against a store boundary or a
snapshot, and the fetch-function seam doubles as the test seam. The third lane delivers the chapter's
best sentence: the snapshot-lane resolve — the full composition, pure, over a defs snapshot — is cheaper
than a single bare get through the boundary. Composition was never the cost; the boundary crossing was.
In the Part II arc the module stands between The CHAMP Property
Database (B2.3) and Relations Are Systems (B2.5).
The dives
three lessons, fixed by the chapter specArchetypes Are Data
The model and the compose fold: a row under ARC, at most one
:extends; an instrument is a reference plus overrides. A1's order proven — tick
0.25 from the instrument, settlement :daily_mark from the archetype, margin true from the base;
the ARC registration as a governance act.
One Definition, a Thousand Instruments
A2 the amplification: one edit, every sampled instrument answers multiplier 100 at next
read, no migration. The economics — an instrument row is 18 words, its composed view
14; West's turn, Gamma's decade, and the baked-views-rejected decision.
The Guards and the Lanes
A3 — one :extends makes the diamond unrepresentable; {:error, :cycle},
{:error, :depth}. A4 — an AST name refused
{:error, :namespace}. A5 — store-lane 5442 ns/op vs snapshot-lane 1048
ns/op against a bare row get is 2653 ns/op.
References
sources · relatedSources
- West — Evolve Your Hierarchythe component turn; the industry-scale retreat from the subclass tree
- Venners — Design Principles from Design PatternsGamma on composition over inheritance, defended a decade on
Related
- B2 — The Elixir BCS Corethe chapter landing; the Part II arc
- B2.2 — Property Stores on ETSthe store family the :archetypes store belongs to
- B2.3 — The CHAMP Property Databasethe forest the snapshot lane resolves against
- B2.5 — Relations Are Systemsthe module the arc continues into
- B1 — Ideas Behindthe law and the identity contract
- Functional Programming in Elixirthe umbrella where echo_data lives