Lably
Skip to content

Proxy pattern

Software design pattern

  • 6 min read
  • 4 chapters

Related on Lably

Through Computer programming and Object-oriented programming

Overview

The proxy design pattern is one of the twenty-three well-known GoF design patterns that describe how to solve recurring design problems to design flexible and reusable object-oriented software, that is, objects that are easier to implement, change, test, and reuse.

Problem

The proxy design pattern is used to solve such problems:

  • The access to an object should be controlled.
  • Additional functionality should be provided when accessing an object.

When accessing sensitive objects, for example, it should be possible to check that clients have the needed access rights.

Solution

Define a separate Proxy object that

  • can be used as a substitute for another object (Subject), and
  • implements additional functionality to control the access to this subject.

This makes it possible to work through a Proxy object to perform additional functionality when accessing a subject, like checking the access rights of clients accessing a sensitive object.

To act as a substitute for a subject, a proxy must implement the Subject interface. Clients can't tell whether they work with a subject or its proxy.

See also the UML class and sequence diagram below.

Sign in to keep reading

3 more chapters are free with a Lably account.

More in Computing and communication