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.
MVC separates an interactive application into three collaborating parts. The Model holds the application's domain data and business logic/state, with no knowledge of any UI. A View is a visual presentation of some part of the Model's current state, purely a renderer with no business logic of its own. A Controller interprets user input/gestures directed at a View and translates them into operations on the Model (or into a switch of the active View).
Collaboration: the Model changes state and notifies its registered Views (typically via the Observer pattern, Question 16) that something changed; each notified View re-renders itself by re-reading the current Model state. A user interacting with a View has that input routed to the associated Controller, which invokes Model operations and/or switches which View is currently displayed. A single Model may drive MULTIPLE Views simultaneously (e.g., the same underlying data shown as both a table and a bar chart, both staying synchronized).
(i) Extensibility — HELPS. Because View and Controller depend on the Model, but the Model holds no reference to any specific View, new Views (or Controllers) can be added for an existing Model with zero changes to the Model or to existing Views — e.g., adding a chart View alongside an existing tabular View of the same data.
(ii) Response time — HURTS (in the naive/default implementation). The Observer-based notification chain, plus the added indirection of routing every user action through a separate Controller object, plus potentially re-rendering several Views on every single Model change even when only one is currently visible, adds genuine overhead compared to a monolithic class that updates its own display directly. Mitigations exist (batching notifications, dirty-flag lazy repaint), but the architecture's default behaviour costs more per user action than a non-separated design.
(iii) Modifiability — HELPS. Each concern can change independently: redesigning the visual presentation (View) does not touch business logic (Model); changing the input mechanism (e.g., a Controller for touch input vs. one for mouse input) does not touch the Model or View classes; changing business rules (Model) never requires touching View/Controller code as long as the Model's notification interface stays unchanged. This isolation is the primary reason MVC is adopted despite its response-time cost.