Skip to main content

Behavioral Patterns: Case Studies

These are synthetic design scenarios, not reports of measured production outcomes. Use the GoF book index for pattern vocabulary and the contracts for executable scope.

Pricing variants​

A checkout adds promotions and carrier policies. Compare a table of fixed values, callables and objects. Choose Strategy only when policy independence, testing or ownership earns the boundary. Require integer-unit and rounding contracts plus a selection table. Failure witness: one provider returns dollars where cents are expected. More classes do not resolve ambiguous policy precedence.

Analytics and views react to accepted payment. Compare direct calls, local Observer and durable queued delivery under explicit requirements. State who owns subscriptions and whether a callback failure affects the caller's result. Failure witness: a callback throws after payment succeeded and the caller retries the payment. A callback exception cannot automatically roll back an external charge.

Editor history​

A drawing editor needs clear, move and recolor undo. Compare immutable snapshots, inverse operations and shared persistent versions under measured memory constraints. Memento captures originator-defined state; Command captures intent/execution. Failure witness: a shallow shape snapshot changes when the live shape mutates. Snapshots are valid when they satisfy the budget; they are not inherently naive.

Document lifecycle​

Draft/review/published/archived has rejected commands and stale approvals. Compare a transition table with State objects. Keep public status/error observations and one state authority. Failure witness: a previous review's approval arrives after revise/submit and is accepted using only the label review. Add generation semantics as an intentional contract extension.

Ordered approvals​

Every required expense check must approve before acceptance. Compare a straightforward function with a handler pipeline. A first-match allow chain is wrong when it skips mandatory checks. Failure witness: manager allow prevents finance rejection from running. Specify ordering, continuation, failure and terminal result before choosing a Chain-shaped implementation.

For each scenario submit one tradeoff memo, one trace and one simpler alternative. These can reuse practice/project evidence; no separate mandatory project count.