Structural Design Pattern: Proxy Design pattern

Level : Intermediate
Mentor: Shailendra Chauhan
Duration : 00:01:00

Define Proxy Design Pattern

Provide an intermediary object that refers to another object. The proxy pattern uses a class named proxy class to represent the functionality of another class.

Types of Proxies

Proxies are classified into three categories. They are as follows.

  1. Virtual Proxy: A virtual proxy serves as a placeholder for items that are "expensive to create". The actual object is only created when a client first requests or accesses it.
  2. Remote Proxy: A remote proxy provides local representation for an object that is located in a separate address space.
  3. Protection Proxy: A protection proxy limits access to a sensitive master object. Before sending the request, the surrogate object ensures that the caller has the necessary access permissions.

Examples of Proxy Patterns

Examples of proxy patterns include:

  • Payment Processing
  • Accessing Remote Service
  • Accessing Remote Database 

Why do we need the C# Proxy Design Pattern?

The Proxy server has two main purposes. They are as follows:

  1. Improve Performance with Proxy Servers
  2. Filter requests using a proxy server.

Proxy Design Pattern with UML Diagram

The UML class diagram above includes the following classes, interfaces, and objects:

  • Subject: This interface defines members that will be implemented by the RealSubject and Proxy classes.
  • RealSubject: This is a class that we wish to use more efficiently with the proxy class.
  • Proxy: This is a class that contains an instance of the RealSubject class and can access its members as needed.

When to use the Proxy Design pattern?

The proxy design pattern is applicable in the following situations:

  • Objects must be produced on-demand, meaning when their activities are requested.
  • Access control to the original object is required.
  • Allow access to a remote object via a local object (which will refer to the remote object).
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this