Skip to main content

Strategy and Template Method Lab

Attempt before opening the separate practice feedback. Keep a prediction, observed result, explanation and changed-assumption case.

P01: Contract before structure​

A checkout policy receives integer cents. Specify inputs, output bounds, rounding ownership and failure. Give one policy with the right signature but wrong units. Compare a function with a policy object.

P02: Captured configuration​

A discount closure captures a mutable configuration dictionary. Change the rate after construction and predict the result. Produce one live-config and one fixed-config version; explain which contract each serves.

P03: One provider​

A product has one shipping provider and needs deterministic tests without network access. Decide whether a boundary earns its cost despite one implementation. Supply a fake and a case where a direct function remains sufficient.

P04: Template failure trace​

Record load, normalize, render, persist, cleanup. Inject a render error and specify which stages run. Compare a template base class with a composed function pipeline. Explain what Python @final can and cannot enforce.

P05: Interchangeability laws​

For comparator behavior define self-comparison, sign reversal and transitivity. Produce a cycle a<b, b<c, c<a that violates the contract. Explain why a mutable clock-based comparator can be unstable. Complete L01.

Submit actual errors and repairs, not a quota. Reuse lab evidence where applicable. See contracts and assessment.