loading...
Cover image for Design Pattern: The Proxy Pattern

Design Pattern: The Proxy Pattern

danlee0528 profile image Daniel Lee 惻2 min read

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.

Another Example

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

Java RMI

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

  1. Make a Remote Interface (define methods)
  2. Make a Remote Implementation
  3. 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.
  4. Start the RMI registry
  5. Start the remote service

Posted on by:

danlee0528 profile

Daniel Lee

@danlee0528

I love interactive & visual technology and playing with data.

Discussion

pic
Editor guide