NivaarExam PrepOfficial exam papers ↗

25-Comp-B11 Advanced Software Design · May 2016

Question 20 of 28: Design Patterns Paramount to GUI Design

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

98-Comp-B11 Advanced Software Design — National Exams, May 2016. 3 hours, closed book exam with one aid sheet allowed (written on both sides), no calculator permitted. The paper is organized into five parts, and candidates were instructed to answer any five (5) questions in Part I, any three (3) in Part II, any four (4) in Part III, any two (2) in Part IV, and any five (5) in Part V — only the first questions answered, in each part, as they appear in the answer book are marked. All questions carry equal weight, so the 19 questions actually marked (5+3+4+2+5 of 28) each count for 100/19 ≈ 5.26% of the paper. All 28 questions are answered below for completeness.

Reference texts: Sommerville, Software Engineering (10th ed., Pearson) — software processes, requirements engineering, agile methods, design principles, dependability; Pressman, Software Engineering: A Practitioner's Approach (9th ed.) — supplementary process and quality coverage; Gamma, Helm, Johnson & Vlissides (GoF), Design Patterns: Elements of Reusable Object-Oriented Software — creational/structural/behavioural pattern catalogue (Singleton, Proxy, Template Method, Observer, etc.); Sebesta, Concepts of Programming Languages (12th ed.) — polymorphism, dynamic binding, inheritance and language-level object semantics; Bertrand Meyer, Object-Oriented Software Construction — design by contract, preconditions/postconditions/invariants, the open–closed principle; Barbara Liskov's 1987 substitutability paper for Question 11; Rogers, Sharp & Preece, Interaction Design, and Nielsen, Usability Engineering, for Question 21's HMI-specific non-functional requirements; Myers, The Art of Software Testing, for Question 28's boundary value analysis.

PART I — General Principles (answer any 5 of 7)

Question 20: Design Patterns Paramount to GUI Design (Part IV)

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.