All Exams Test series for 1 year @ ₹349 only
Question

A software design pattern often used to restrict access to an object is:

The correct answer is

proxy

Understanding Software Design Patterns for Access Control

Software design patterns are reusable solutions to common problems encountered during software development. They represent best practices that developers can apply to create flexible, maintainable, and efficient code.

The question asks for a specific design pattern used to restrict access to an object. Let's look at the options provided:

Analyzing the Given Design Patterns

  • Adapter Pattern: The Adapter pattern is used to convert the interface of a class into another interface clients expect. It allows classes with incompatible interfaces to work together. It focuses on interface compatibility, not restricting access to an object.
  • Decorator Pattern: The Decorator pattern is used to add new functionality to an object dynamically without altering its structure. It wraps the original object, providing enhanced or altered behavior. While it wraps the object, its primary purpose is adding responsibilities, not restricting access based on conditions or permissions.
  • Delegation: Delegation is a technique where one object relies on another object to fulfill a task. It's a way of composing objects to achieve desired behavior, often used in patterns like Strategy or State. While related to object interaction, it's a mechanism for forwarding calls, not a pattern specifically designed to control whether calls are allowed in the first place for security or resource management reasons in the way the question implies restriction.
  • Proxy Pattern: The Proxy pattern provides a surrogate or placeholder for another object to control access to it. This control can include various forms of restriction, such as lazy initialization (delaying object creation until needed), access control (checking permissions before allowing method calls), logging requests, or counting references. The core idea is that the proxy object stands in for the real object and manages interactions with it.

Based on the purpose of each pattern, the one specifically designed to control or restrict access to another object is the Proxy pattern.

The Proxy pattern acts as an intermediary. Clients interact with the proxy, and the proxy manages the interaction with the real object. This allows the proxy to perform actions before or after forwarding requests to the real object, including preventing access entirely under certain conditions.

Conclusion on Access Restriction Pattern

Among the given options, the Proxy pattern is the standard design pattern whose primary function includes providing controlled access to another object. This fits the description of restricting access.

Design Pattern Comparison
Pattern Primary Purpose Access Restriction
Adapter Interface Compatibility No
Decorator Adding Functionality Dynamically Indirect (by wrapping), but not primary goal
Delegation Forwarding Requests No (mechanism, not a pattern specifically for control)
Proxy Controlled Access / Surrogate Yes (explicitly part of its definition)

Revision Table: Key Design Patterns

Software Design Pattern Types
Category Description Examples (Relevant here)
Structural Patterns Deal with the composition of classes and objects. Adapter, Decorator, Proxy
Behavioral Patterns Deal with algorithms and the assignment of responsibilities between objects. Delegation (often used within these)
Creational Patterns Deal with object creation mechanisms. Factory Method, Abstract Factory, Singleton

Additional Information on Proxy Pattern and Access Control

The Proxy pattern is part of the Structural Patterns category as defined by the Gang of Four (GoF) in their seminal book "Design Patterns: Elements of Reusable Object-Oriented Software".

Different types of proxies exist, each serving a specific purpose related to access control or management:

  • Remote Proxy: Represents an object located in a different address space. Controls access to the remote object.
  • Virtual Proxy: Controls access to an object that is expensive to create. It defers the creation of the object until it is actually needed (lazy initialization).
  • Protection Proxy: Controls access to the real object based on permissions. This is the type most directly related to "restricting access" in a security or permission-based sense.
  • Smart Reference Proxy: Performs additional actions whenever the real object is accessed, such as counting references or loading the object into memory.

In all these cases, the proxy serves as a gatekeeper or manager for the underlying real object, thereby controlling or restricting direct access to it from the client.

Was this answer helpful?

Important Questions from Design and Analysis

  1. Which of the following UML diagrams has a static view ?

  2. Match the following in Software Engineering:

    List – I

    List – II

    (a)

    Product Complexity

    (i)

    Software Requirements Definition

    (b)

    Structured System Analysis

    (ii)

    Software Design

    (c)

    Coupling and Cohesion

    (iii)

    Validation Technique

    (d)

    Symbolic Execution

    (iv)

    Software Cost Estimation

  3. Software validation mainly checks for inconsistencies between

  4. Which of the following statements is/are TRUE?

    P: In software engineering, defects that are discovered earlier are more expensive to fix

    Q: A software design is said to be a good design, if the components are strongly cohesive and weakly coupled

    Select the correct answer from the options given below:

  5. Which of the following are the primary objectives of risk monitoring in software project tracking?

    P: To assess whether predicted risks do, in fact, occur
    Q: To ensure that risk aversion steps defined for the risk are being properly applied
    R: To collect information that can be used for future risk analysis

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App