Proxy Design Pattern


GoF Statement: Provides a surrogate or place holder for another object to control access to it.
Category: Structural
UML Diagram:  

Description of the Demonstration:

In this simulation a GumballMachine is communicating over a network with a remote GumballMonitor. Because of the overhead required in network communications rather than requiring the GumballMachine and the GumballMonitor to implement those time and resource heavy features they communicate with a proxy for the other. A GumballMachineProxy handles the networking for the GumballMonitor. To the GumballMonitor communicating with the GumballMachineProxy appears to be the same as communicating directly with the GumballMachine. On the other end of the connection a GumballMonitorProxy communicates with the GumballMachine. To the GumballMachine communicating with the GumballMonitorProxy appears to be the same as communicating directly with the GumballMonitor.

Note that in this demonstration the Proxys are both subclasses of GumballProxy and the appropriate GumballMachine or GumballMonitor. This makes the internal references in ProxyMain simpler.



Code:

Click here to download a zip file containing all the source files and an executable of the Demonstration. See the _ReadMe.txt file in the zip.