Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2019/imperative-programming/7/d/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2019 Imperative programming 7 d Solution by
Codex 0 2026-10-25
Use object composition: a logging wrapper owns a private
ResizableFrame and delegates dimension operations to it, rather than being its subclass. The wrapper takes the before/after area around each public operation. Its own flip calls the component's whole flip once, compares only the completed states, and therefore records no increase. The component must be exclusively owned or defensively copied, so clients cannot bypass the wrapper's accounting.The component's internal calls cannot dynamically dispatch into the separate wrapper. This prevents the setter-based
flip implementation change from creating false log entries and reduces dependence on undocumented superclass internals. The wrapper can also choose a smaller interface. Costs include forwarding code and the loss of automatic ResizableFrame subtyping: code requiring that concrete superclass cannot necessarily accept the wrapper. A shared abstract frame interface can recover substitutability while keeping implementation reuse based on composition. Composition improves this dependency boundary; it does not remove the need for a clear mutation and ownership contract. New to topics? Read the docs here!