25-Comp-B11 Advanced Software Design · May 2016
Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer) · Last updated
Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.
Composite. A GUI widget tree (a Window containing Panels containing Buttons/Labels and further nested Panels) is the canonical Composite structure: individual widgets (leaves) and containers of widgets (composites) are treated UNIFORMLY through a common Component interface (e.g., draw(), layout(), handleEvent()), letting the framework recursively render, lay out, and dispatch events through an arbitrarily deep widget tree using the SAME code, without ever special-casing "is this a single widget or a container." Virtually every GUI toolkit's scene graph or widget hierarchy is built as a Composite.
Observer. A GUI display must stay synchronized with underlying application/model state without the Model needing any knowledge of which, or how many, Views currently display it (Question 18) — each widget registers as an Observer of the Model (or of a lower-level GUI-side model such as a list/table model) and is notified to repaint itself whenever that state changes. Without Observer, the Model would need direct references to every UI component displaying it, coupling business logic to specific UI classes — exactly the coupling Question 19 argues against.
Justification for these two over the other six. Composite and Observer are the two patterns a GUI toolkit fundamentally CANNOT be built without: a toolkit has no way to represent a widget hierarchy at all without Composite, and no way to keep any display synchronized with changing data without Observer. The remaining six (Adapter, Bridge, Command, Decorator, Façade, Proxy) are all genuinely useful in GUI work — Command in particular is strong for decoupling menu items/toolbar buttons from the action they trigger and enabling undo/redo — but each solves a narrower sub-problem layered on top of a widget tree (Composite) that stays synchronized with data (Observer), rather than being foundational to the toolkit's own existence.