The Proxy Pattern provides a surrogate or placeholder for another object to control access to it. You may want to use this pattern to create a representable object that controls access to another object, which may be remote, expensive to create or in need of securing.
- The client is calling methods on a heap-local 'proxy' object that handles all the low-level details of network communication.
There are also other notable types of Proxy and many variations: virtual and protection
- A virtual proxy is used to control access to an object that is expensive to instantiate
- A protection proxy is used to control access to the methods of an object based on the caller
In Java, Java RMI (Remote Method Invocation) can help you build the client and service helper objects with the same methods as the remote service. It provides all the runtime infrastructure to make it all work including a lookup service that the client can use to find and access the remote objects.
Making the Remote Service
- Make a Remote Interface (define methods)
- Make a Remote Implementation
- Generate the stubs and skeletons using RMIC (part of Java RMI)
- A method stub or simply stub in software development is a piece of code used to stand in for some other programming functionality. A stub may simulate the behaviour of existing code or be a temporary substitute for yet-to-be-developed code.
- Start the RMI registry
- Start the remote service