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. proxyCONCEPT — A structural design pattern can interpose a stand-in between a client and a real object while preserving the interface the client expects. The…

  1. A.

    adapter

  2. B.

    decorator

  3. C.

    delegation

  4. 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.

  1. The client calls read() on an object that implements the document interface.

  2. A stand-in implementing the same interface receives the call first and checks the caller’s permissions.

  3. The stand-in forwards an authorized call to the real document object and rejects an unauthorized call.

  4. 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: Nta Ugc Net Paper 2

Loading lesson…