Proxy Design Pattern

Learn about the proxy pattern, its purpose, applicability, and structure, as well as related design patterns.

Overview

Suppose that we have a very sensitive object, and we don’t want the client to access it directly. Or, we have an object that is very expensive to create. We certainly want to limit access to the objects in these cases. This is where we would use the proxy pattern.

In the proxy pattern, we introduce a middleman (surrogate) that will interact with the real object. Through this proxy (surrogate), we can limit access to the original object. It will also help us hide the detail of the real objects from the client.

Type

The proxy is a design pattern from software development that belongs to the category of structural patterns.

Purpose

It provides a placeholder for another object to control access to it.

Also known as

The proxy pattern is also known as a surrogate.

Applicability

The proxy pattern can be used through multiple methods, but here are a few of the most important:

  • Virtual proxy: This type of proxy is used when we need to deal with a resource-intensive object. Through the virtual proxy, we’ll only initialize the object when we need it.

  • Protection proxy: This proxy is used when we want to only give access to authorized clients. The proxy will only allow authorized access to a protected object.

  • Remote proxy: This proxy provides a local representative for an object that lies remotely.

Structure

Get hands-on with 1400+ tech skills courses.