AlgoViz

Choose a function, class or interface

medium 12 min

Select 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

ChoiceOwnsChange that justifies it
FunctionWeight-to-price calculationDifferent table data
Carrier clientConnection and timeoutLive carrier quotes
Provider interfaceCaller’s common contractA 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

SignalExample
WeakAsk for the cleanest pattern without describing what varies.
CompetentAll required inputs are explicit and no resource has a lifecycle.
StrongThe 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?

Sources