Hacker News new | ask | show | jobs
by dbaupp 3549 days ago
That has downsides like, for one, requiring allocations for every state transition, and the runtime infrastructure (plus loss of static assurances) required to do downcasts when one needs functionality that only exists on a specific state. For closed state spaces like this example, a discriminated union is far more controlled and has many advantages, whereas subclassing is often better suited to open (or large) sets of states.