Replace a Type Switch Only When Variants Own Behavior
Apply Replace Conditional with Polymorphism when branch variants carry different behavior.
Move subscription pricing branches out of a central type switch without changing existing prices. Replace Conditional with Polymorphism: stable variants own their behavior behind a common protocol. Turning every conditional into classes creates ceremony. The pattern earns its keep only when branches represent real variants with different behavior and future change pressure. Characterize branch behavior Add tests for trial, nonprofit, enterprise, education, and legacy prices. Before moving branches, pin current outcomes for each variant. Create the shared protocol Define PlanPricing.priceFor(account) and keep the current switch as the selector. The interface names the behavior callers need, not every plan field. Move…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in