NivaarExam PrepOfficial exam papers ↗

25-Comp-B11 Advanced Software Design · May 2014

Question 14 of 25: Uses of the Proxy Design Pattern

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

Notes on this paper

98-Comp-B11 Advanced Software Design — National Exams, May 2014. 3 hours, open book, no calculator permitted. The paper is organized into five parts, and candidates were instructed to answer any three (3) questions in Part I, any four (4) in Part II, any three (3) in Part III, any one (1) in Part IV, and any one (1) 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 12 questions actually marked (3+4+3+1+1 of 25) each count for 100/12 ≈ 8.3% of the paper. All 25 questions are answered below for completeness.

Reference texts: Sommerville, Software Engineering (10th ed., Pearson) — software processes, requirements engineering, agile methods, design principles; 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 — structural/behavioural pattern catalogue (Proxy, Bridge, Strategy, Observer, Template Method, Composite, etc.); Sebesta, Concepts of Programming Languages (12th ed.) — polymorphism, dynamic binding, inheritance and language-level object semantics (also underpins the Java/C++ discussion in Part V). Bertrand Meyer's Object-Oriented Software Construction is cited by name where the paper's own vocabulary (design by contract, open–closed principle) originates there; Barbara Liskov's 1987 substitutability paper is likewise cited by name for Question 11.

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

Question 14: Uses of the Proxy Design Pattern (Part III)

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.

Proxy provides a surrogate object that controls access to a "real subject" object, implementing the same interface so a client is unaware whether it holds the proxy or the real object.

  1. Remote proxy. Represents an object living in a different address space or on a different machine (an RMI/CORBA stub). The proxy marshals the method call's arguments, sends them across the network to the real object, waits for the reply, and unmarshals the result — hiding all networking and serialization detail so the client's code looks exactly like a local method call.
  2. Virtual proxy. Defers creation of an EXPENSIVE real object until it is actually needed (lazy instantiation). A document editor containing large embedded images can display a lightweight stand-in proxy for each image immediately on open, and only load the full bitmap from disk the first time that image is actually scrolled into view or rendered — saving startup time and memory for images the user never actually views.
  3. Protection proxy. Controls access to the real object based on the caller's permissions. The proxy checks the current caller's access rights before forwarding (or refusing) a request to the real subject, centralizing authorization logic in one place without modifying the real subject's own code — e.g., a proxy placed in front of a sensitive document object checks the current user's role before allowing a read or write call to reach the real document.

All three share the same structural shape: Proxy and RealSubject both implement a common Subject interface, and the client holds only a Subject-typed reference, so it never needs to know which one it actually has.