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 :
- A.
adapter
- B.
decorator
- C.
delegation
- D.
proxy
Attempted by 126 students.
Show answer & explanation
Correct answer: D
Answer: proxy
Why proxy is correct:
A proxy acts as a surrogate or placeholder for another object and can control how and when requests reach the real object.
A protection proxy specifically enforces access control (for example, checking credentials or permissions before allowing an operation).
Other proxy variants (virtual proxy, remote proxy, caching proxy) also control access or visibility in different ways, making proxy appropriate when you need to restrict, mediate, or manage access.
When to use a proxy:
To enforce access control or security checks before forwarding requests.
To add logging, caching, or lazy initialization while keeping the real object unchanged.
Why the other patterns are not correct:
Adapter: Converts one interface into another so classes can work together; it adapts interfaces but does not restrict access.
Decorator: Wraps an object to add or modify behavior dynamically; it enhances functionality rather than serving as an access gate.
Delegation: A technique where an object delegates work to another object; it is not primarily a pattern for restricting access.
A video solution is available for this question — log in and enroll to watch it.