design-patterns

  • Union types, promotion, and match

    8.0 shipped in November with three changes that alter how a class is written, and a fourth that quietly breaks string-to-number comparison.

  • Constructor promotion, and the value object that is four lines

    A value object was a property declaration, a constructor parameter and an assignment for every field — three lines each, all of them saying the same thing. The…

  • Enum-like class constants, and the three things they cannot do

    Enums are 8.1, so a set of allowed values in 2020 is class constants with a validating constructor — and the gaps are worth naming rather than discovering.…

  • Covariant returns unblock a factory interface

    A child class overriding a method had to declare exactly the parent’s return type, so an abstract repository could not promise that each implementation returns its own entity.…

  • A unique index arbitrates; a SELECT does not

    Checking whether a key exists and then inserting it is two statements, and two requests can both pass the check before either inserts. The unique index is what…

  • Configuration binding, and the options pattern

    Reading configuration by key from a dictionary means every consumer knows the key names and nothing validates them; binding to a class means the shape is declared once.…

  • PSR-14 event dispatching, and the interface everyone can implement

    Every framework had an event dispatcher and none of them shared an interface, so a library wanting to emit events either picked one or invented its own. The…

  • A composable is a function, which is the whole idea

    A mixin merges properties into a component with no indication of where anything came from, and two mixins defining the same name silently collide. The call site names…

  • Vue 3 and the Composition API

    A 600-line component with a mixin nobody could trace. The Composition API is not a new way to write components — it is a way to move logic…

  • Block patterns, and the page an editor can build

    Eleven custom blocks that exist to produce one layout. 5.5 added patterns, which is the feature the blocks were being used for — and it needs no build…