![]() |
CS 635: Advanced Object-Oriented Design & Programming |
|---|
| References | slide # 1 |
| Proxy | slide # 2 |
| ...Structure | slide # 2 |
| ...Dynamics | slide # 3 |
| ...Reasons for Object Proxies | slide # 4 |
Pattern-Oriented Software: A System of Patterns, Buschman, Meunier, Rohnert, Sommerlad, Stal, 1996, pp 263-275
Advanced C++: Programming Styles and Idioms, James Coplien, 1992, pp 58-72
CS 635 Lecture notes, 1998, Doc 22 http://www.eli.sdsu.edu/courses/spring98/cs635/notes/bridge/br idge.html

Use common interface (or abstract class) for both the proxy and original object
Proxy contains a reference to original object, so proxy can forward requests to the original object



public class HelloClient {
public static void main(String args[]) {
try {
String server = getHelloHostAddress( args);
Hello proxy = (Hello) Naming.lookup( server );
String message = proxy.sayHello();
System.out.println( message );
}
catch ( Exception error)
{ error.printStackTrace(); }
}
}
public class Table {
public Object elementAt( int row, int column ){ blah }
public void setElementAt(Object element, int row, int column )
{ blah}
}
public class RowLockTable {
Table realTable;
Integer[] locks;
public RowLockTable( Table toLock) {
realTable = toLock;
locks = new String[ toLock.numberOfRows() ];
for (int row = 0; row< toLock.numberOfRows(); row++ )
locks[row] = new Integer(row);
}
public Object elementAt( int row, int column ) {
synchronized ( locks[row] ) {
return realTable.elementAt( row, column);
}
}
public void setElementAt(Object element, int row, int column ){
synchronized ( locks[row] ) {
return realTable.setElementAt(element, row, column);
}
}
}
See Doc 22 slides 9-11
These two elements are used to construct communicating objects
and classes that solve a general design problem in a particular
context
The structures of different patterns may be similar but the problem
each pattern solves is different
Different pattern's problems may overlay at times
The goal is not to produce a disjoint taxonomy of structures but a list of common problems and a general structure for solving them