Home » Blog » Software Development » Software Design Patterns in PlantUML » Design Pattern with PlantUML: Proxy Pattern

Design Pattern with PlantUML: Proxy Pattern

This post gives a brief overview about the Proxy Pattern. The post is part of a series about software design patterns and their UML representations with the help of PlantUML.

The article aims at providing a very short description of the general idea of the pattern in the first part. This also involves a descriptive UML diagram. Then, the second part provides the PlantUML code for the diagram so that these posts can also be used as a source of design patterns in PlantUML syntax.

What is the Proxy Pattern?

According to Wikipedia, a proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. In short, a proxy is a wrapper or agent object that is being called by the client to access the real serving object behind the scenes. Use of the proxy can simply be forwarding to the real object, or can provide additional logic.

What problems can the Proxy design pattern solve?

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

What solution does the Proxy design pattern describe?

Define a separate Proxy object that

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

This enables to work through a Proxy object to perform additional functionality when accessing a subject. For example, to check the access rights of clients accessing a sensitive object.
To act as substitute for a subject, a proxy must implement the Subject interface. Clients can’t tell whether they work with a subject or its proxy.

UML Diagram

The following diagram shows the Proxy Pattern in UML notation. It is based on the corresponding chapter in the book “Head First Design Patterns“:

PlantUML Syntax:
<p>@startuml<br />
interface Subject {<br />
{abstract} request()<br />
}<br />
together {<br />
class RealSubject<br />
class Proxy<br />
}</p>
<p>RealSubject : request()<br />
Proxy : request()</p>
<p>Subject <|.. RealSubject<br />
Subject <|.. Proxy<br />
RealSubject <- Proxy : subject</p>
<p>note bottom of RealSubject<br />
The RealSubject is<br />
usually the object<br />
that does most<br />
of the real work;<br />
the Proxy controls<br />
access to it.<br />
end note</p>
<p>note “The Proxy often instantiates\nor handles the creation of\nthe RealSubject.” as n1</p>
<p>RealSubject .. n1<br />
Proxy .. n1</p>
<p>note right of Subject<br />
Both the Proxy and the<br />
RealSubject implement the<br />
Subject interface. This<br />
allows any client to treat<br />
the proxy just like the<br />
RealSubject.<br />
end note<br />
@enduml</p>

PlantUML Sources

PlantUML is a tool allowing users to create UML diagrams from a plain text language. Here are the PlantUML sources for the above software pattern:

@startuml
interface Subject {
{abstract} request()
}
together {
class RealSubject
class Proxy
}

RealSubject : request()
Proxy : request()

Subject <|.. RealSubject
Subject <|.. Proxy
RealSubject <- Proxy : subject
@enduml

Other Design Patterns

In another article you find information about how to put together a single-side web application using PlantUML.

Proxy Pattern Design Pattern with PlantUML: Proxy Pattern - This post gives a brief overview about the Proxy Pattern. The post is part of a series about software design ... Read More
State Pattern Design Patterns with PlantUML: State Pattern - This post gives a brief overview about the State Pattern. The post is part of a series about software design ... Read More
Composite Pattern Design Patterns with PlantUML: Composite Pattern - This post gives a brief overview about the Composite Pattern. The post is part of a series about software design ... Read More
Iterator Pattern Design Patterns with PlantUML: Iterator Pattern - This post gives a brief overview about the Iterator Pattern. The post is part of a series about software design ... Read More
Template Pattern Design Patterns with PlantUML: Template Pattern - This post gives a brief overview about the Template Pattern. The post is part of a series about software design ... Read More
Facade Pattern Design Patterns with PlantUML: Facade Pattern - This post gives a brief overview about the Facade Pattern. The post is part of a series about software design ... Read More
Adapter Pattern Design Patterns with PlantUML: Adapter Pattern - This post gives a brief overview about the Adapter Pattern. The post is part of a series about software design ... Read More
Command Pattern Design Patterns with PlantUML: Command Pattern - This post gives a brief overview about the Command Pattern. The post is part of a series about software design ... Read More
Singleton Design Patterns with PlantUML: Singleton - This post gives a brief overview about the Singleton Pattern. The post is part of a series about software design ... Read More
Design Patterns with PlantUML: Abstract Factory Pattern - This post gives a brief overview about the Abstract Factory Pattern. The post is part of a series about software design ... Read More

Check Also

State Pattern

Design Patterns with PlantUML: State Pattern

This post gives a brief overview about the State Pattern. The post is part of …

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

We use Cookies and similar technology to collect and analyse information about the users of this website. We use this information to enhance the content, advertising and other services available on the site. Please click ‘Accept cookies’ to consent to the use of this technology by petrockblock. You can manage your preferences at any time by visiting our Cookies Policy page.