Choose a function, class or interface
medium 12 minSelect an abstraction by the responsibility it owns and the cost of replacing it.
Theory
Read or listen first. About 1 min.
What it is
A delivery service quotes shipping from a published rate table. Its generated design introduces a QuoteFactory, a QuoteStrategy and an adapter for a lookup that never leaves memory.
Why it exists
Trace what can vary. Here only the table varies, so pass data into a pure function. An object becomes useful when a carrier client owns credentials, rate limits or a connection lifecycle. At that point its boundary should expose the quote the caller needs, plus a meaningful failure result.
Remove a layer and observe the cost
| Choice | Owns | Change that justifies it |
|---|---|---|
| Function | Weight-to-price calculation | Different table data |
| Carrier client | Connection and timeout | Live carrier quotes |
| Provider interface | Caller’s common contract | A second independent provider |
Understand it
Work through the decision
Keep a concrete function for the table. It is straightforward to test at band edges and has no lifecycle.
Put a narrow interface in front of remote providers when their independent failure and substitution matter. Every extra type costs a reader another jump.
Give the agent a check
- Ask for the smallest implementation for a static table, then explain the concrete requirement that would justify a provider interface.
The shortcut
- Ask for the cleanest pattern without describing what varies.
What a reviewer can hear
| Signal | Example |
|---|---|
| Weak | Ask for the cleanest pattern without describing what varies. |
| Competent | All required inputs are explicit and no resource has a lifecycle. |
| Strong | The upper bound of a price band, the first value in the next band and the policy for invalid weights. |
Summary
The whole topic in one minute.
Pull out the wrapper. Which promise disappeared?