Skip to main content

Construction, Copies, Trees and Lazy Resources

This workshop replaces the old “15 implementations” inventory within original core practice. It does not replace the adapter/retry/cleanup extension or SC1–SC6. Keep the module at 65–95 hours: original core practice 21–31 = reasoning/tasks 10–14, executable work 8–12, experiments 3–5. Lessons, core assessment and the extension retain their existing allocations. One artifact can support multiple tasks when the distinct claim is explained.

Download the core kit. Read its contracts.md, run python3 check.py starter, implement the five groups, and preserve your first failures. Initial NotImplementedError is intentional. Use py -3 on native Windows. Only after attempting, compare reference.py and run python3 check.py reference. No network, GUI toolkit or real provider is required. Existing practice pages supply design alternatives; the following tasks make evidence concrete.

Family construction — P01–P04​

  • P01: predict the exact factory call sequence and result for two matching dark-family products. Name which part of the contract a shape check cannot establish.
  • P02: inject a light scrollbar after a dark button. Preserve a failing test and the rejection. Explain why one class named AbstractFactory would not itself prevent the mismatch.
  • P03: compare a callable factory and an object with two creation methods. Implement one and sketch the other's public contract; introduce a third product and count actual edit locations.
  • P04: let second-product construction fail after the first acquired a resource. Explain why this kit does not roll back that resource; connect the case to the existing open_bundle extension. Do not invent rollback guarantees.

Request construction — P05–P08​

  • P05: enumerate GET/POST crossed with None, empty string and nonempty body. Predict which combinations this specific API accepts before running.
  • P06: mutate caller headers after construction, then mutate returned headers. Show both isolation directions.
  • P07: compare a validating function with a fluent builder. Add an optional timeout and a cross-field condition; identify when validation can happen and when the complete state is needed.
  • P08: reject a request and preserve the previously built request. Explain why progressive construction need not imply a partially valid published object.

Prototype topology — P09–P12​

  • P09: copy a dictionary whose left/right keys share one list. Draw source and clone identities; explain shallow versus deep copying.
  • P10: mutate one cloned child and inspect the other cloned alias and original. Preserve the prediction and actual observation.
  • P11: clone a list containing itself. Verify the clone's self-reference without recursively printing the graph. Explain the role of memoized identity tracking.
  • P12: change the requirement so a borrowed service must remain shared. Explain why blindly deep-copying the entire object is now wrong. Design an explicit copy policy; do not apply this kit to live sockets.

Composite contracts — P13–P16​

  • P13: derive the total of [2,[3,[],4]] and the empty list. State the combination identity and leaf domain.
  • P14: let branch=[2,3] and evaluate [branch,branch]. Explain why a global visited set would undercount occurrence semantics.
  • P15: add a cycle on the active path; reject it rather than recurse forever. Compare an active-path identity set with a global deduplication policy.
  • P16: introduce an inventory requirement that counts unique physical items. Give a counterexample showing why the old occurrence contract must change. Discuss recursion depth separately from cycle safety.

Proxy, scope and judgment — P17–P20​

  • P17: predict create/read/read/close/close and close-before-read traces. Show that only successful acquisition is retained.
  • P18: distinguish acquisition failure from a later read failure. Demonstrate retry in the former and cleanup of the acquired resource in the latter. Explain the contract's no-failing-close assumption.
  • P19: compare this owning lazy proxy with a caching proxy and a decorator. Identify what state each retains and which effects need separate reasoning. A thread-safe cache does not imply exactly one underlying call.
  • P20: replace one unnecessary abstraction in your chosen example with a function or direct value construction. Keep a before/after observable trace and explain the change pressure that would make you reconsider.

Three experiments​

E1 — Ownership: compare assignment, shallow copy and deep copy on the same shared-child fixture. Predict identity, mutation visibility and memory tradeoffs; retain observations, not a claim that deep copy is always safer.

E2 — Extension surface: add one product to a two-product family, then one new family. Count changed interfaces, implementations, client branches and tests for callable/object alternatives. Your counts describe these implementations, not a universal complexity law.

E3 — Lifetime: run lazy acquire/use/release plus close-before-use and failed-acquire cases. Record which party owns cleanup. Extend the design on paper to a borrowed resource and explain why blindly closing it is unsafe.

Integrated design project​

Use one document-export or small screen-construction feature. State its input/ownership/failure contract, implement the smallest design, add a changed product or output requirement and preserve tests plus an alternatives note. Use patterns only where they meet actual pressure. Reuse P03/P12/P20 and extension traces; no new application or second portfolio is required. Keep live provider, concurrency and external-effect claims outside the finite kit's guarantees.

Apply core and SC gates; read practice calibration and independent assessment solutions only after attempting. Source lookup: Python copy semantics, cache concurrency limits, and separating configuration from use. These explain mechanisms; the contracts and exercises here are original.