Design Principles

Two bounded design principles for Python, and the part refactoring catalogues leave out: exactly where each one stops. Principle 1 — a parameter's type should name the smallest capability the function actually exercises, not the concrete class the caller happens to hold. Principle 2 — branching on what something *is* in order to decide what to *do* is a missing polymorphism. Use this skill when deciding whether an abstraction is warranted at all: should this parameter be a Protocol or ABC, should this type be split, is this if/elif chain acceptable, is `X | None` the honest signature, am I widening `list` to `Iterable` truthfully, does this validator mean the type is really several types. Use it when a reviewer asks for "less coupling" or "more abstraction" and you need to judge whether they are right, and before adding any interface, Protocol, ABC, or base class. To instead sweep an existing package for branch-based discrimination, use the polymorphism-over-discrimination skill.

wolski Updated

File contents

wolski/wews_skill_coordinator/tree/main/skills/software-engineering/skills/design-principles commit edb2ed062c

Frequently asked questions

npx skillmds@latest add wolski/design-principles