Monday, August 1, 2016

Proxy Design Pattern

The Proxy Design Pattern is a structural pattern that provides an object representing another object. This "proxy" acts as an intermediary to control access to the real object, which is often more complex or expensive to create. Proxies can be used for various purposes, including access control, lazy loading, logging, and more.

Here are some real-time use cases for the Proxy Design Pattern:

1. Virtual Proxy for Lazy Loading

  • Scenario: Loading a resource-intensive object (e.g., a large image or document) should be deferred until it is actually needed to save on initial loading time and resources.
  • Proxy Use Case: Implement a VirtualProxy that delays the creation and loading of the real object (e.g., LargeImage) until it is accessed. This proxy handles the initialization of the resource only when necessary.

2. Remote Proxy for Network Communication

  • Scenario: An application needs to interact with objects that are located on a remote server, potentially over a network.
  • Proxy Use Case: Implement a RemoteProxy that handles communication with a remote object (e.g., RemoteService) by sending requests over the network. The proxy abstracts the details of network communication from the client.
  • Proxy used in Java API:  java.rmi.*;


No comments:

Post a Comment