Intent

Use a simple object to represent a complex one or provide a placeholder for another object to control access to it.

Where to use & benefits

Structure


Participants

Proxy  (IShapeDrawer)
maintains a reference that lets the proxy access the real subject. Proxy may refer to a Subject if the RealSubject and Subject interfaces are the same.

Subject  (RectangleShape, CircleShape, TriangleShape)
defines the common interface for RealSubject and Proxy so that a Proxy can be used anywhere a RealSubject is expected.

RealSubject  (ShapeGraphicsDrawer)
defines the real object that the proxy represents.

Example

In the demonstration application, the drawShape() request to the shape (Rectangle, Trinagle, Circle) object act as a proxy and the actual implementation is provided in the ShapeGraphicsDrawer class which draws the shape using graphics object.

Class Diagram


Source Code Links