Introduction

The Proxy design pattern provides a surrogate or placeholder for another object to control access to it. Moreover, it is used as often as (4/5). Next, we see the UML diagram of Proxy.

UML Class Diagram

Program Implementation

Advantage

  1. Proxy object can extend the functionality of the target object
  2. Proxy pattern can separate Client and target object to reduce the coupling of the system and increase the extensibility of the program.
  3. Proxy Pattern has the role of mediator and protect the target object.

Disadvantage

  1. it will increase the number of classes in the system design
  2. A proxy object is added to the Client and the target object, which will slow down the request processing speed.
  3. increases the complexity of the system

Usage

  1. Remote Proxy: Let an object with a different address provide a representative object of a region. For example, it is possible to turn a service in the United States into a part of a service in Taiwan through a proxy mode
  2. Virtual proxy: Postpone the creation of an object that requires a lot of resources until it is really needed. For example, if the image file is too large when loaded, a small image Proxy is used to replace the real image
  3. Protection proxy: This proxy is usually used to control the access rights of different kinds of Clients to RealSubject. For example: the membership level of the forum
  4. intelligent proxy: used to call the target object, the proxy additional some additional functions. For example: record the traffic of access
  5. Delayed loading: In order to improve system performance, and direct loading of the target. For example: delayed loading of attributes in Hibernate

Reference

  1. C# Proxy Design Pattern — Dofactory
  2. [Day21] 代理模式 | Proxy Pattern — iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天 (ithome.com.tw)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store