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 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.
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. [...]
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 patterns and their UML representations with the help of PlantUML. [...]
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 patterns and their UML representations with the help of PlantUML. [...]
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 patterns and their UML representations with the help of PlantUML. [...]
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 patterns and their UML representations with the help of PlantUML. [...]
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 patterns and their UML representations with the help of PlantUML. [...]
Leave A Comment
You must be logged in to post a comment.