The Proxy pattern is another common pattern that is heavily utilized by DCOM and .NET remoting.
• In the proxy pattern, one object acts as a surrogate object for one or more actual objects, and forwards calls to these objects.
• By doing so, the proxy objects presents a level of indirection to the actual object, and this level of indirection could be used to perform many functions before access to the actual object might be allowed.
• In the DCOM and .NET remoting frameworks, the proxy object is used to marshal data over to a remote process.
• Proxies can also be used to add a level of access checks that are used to grant or deny access to the actual object, or to group multiple calls to an object into one single call to improve performance.
namespace Patterns {
interface IMath {
int Add(int x, int y);
int Subtract(int x, int y);
}
class BigMathClass : IMath {
public int Add(int x, int y) {
return x + y;
}
public int Subtract(int x, int y) {
return x - y;
}
}
class Proxy : IMath {
//(Proxy => Provide a surrogate or placeholder for another object to control access to it.)
BigMathClass _m = new BigMathClass();
public int Add(int x, int y) {
return _m.Add(x, y);
}
public int Subtract(int x, int y) {
return _m.Subtract(x, y);
}
}
}Links: