A software design pattern often used to restrict access to an object is:
2018
A software design pattern often used to restrict access to an object is:
Answer: D. proxy — CONCEPT — A structural design pattern can interpose a stand-in between a client and a real object while preserving the interface the client expects. The…
- A.
adapter
- B.
decorator
- C.
delegation
- D.
proxy
Attempted by 240 students.
Show answer & explanation
Correct answer: D
CONCEPT — A structural design pattern can interpose a stand-in between a client and a real object while preserving the interface the client expects.
The stand-in mediates requests before they reach the real object. When that mediation checks permissions or denies operations, it is providing access control.
APPLICATION — Consider a document service with a read() operation that should be available only to authorized users.
The client calls read() on an object that implements the document interface.
A stand-in implementing the same interface receives the call first and checks the caller’s permissions.
The stand-in forwards an authorized call to the real document object and rejects an unauthorized call.
This same-interface surrogate that controls access is a protection proxy, so the applicable pattern is proxy.
CROSS-CHECK / CONTRAST — Compare the intent of each offered term.
Adapter translates one interface into another expected interface.
Decorator keeps the interface while adding responsibilities to an object.
Delegation transfers responsibility for an operation to another object.
Proxy keeps the subject interface while mediating access to the real subject.
RESULT — The pattern used to restrict access to an object is proxy.
A video solution is available for this question — log in and enroll to watch it.
Explore the full course: Mppsc Assistant Professor Computer Science Paper 2