Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (1) –A structural design pattern.

Similar presentations


Presentation on theme: "Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (1) –A structural design pattern."— Presentation transcript:

1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (1) –A structural design pattern –Intent Provide a surrogate or placeholder for another object to control access to it

2 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (2) –Problem Situation I: Wish to control access to an object because: –Housekeeping activities are required –Protection levels exist –Objects sit in different address spaces –Actual object too expensive to build immediately Situation II: Wish to provide transparent management of services –The client “thinks” it is using the actual service when rather it is using a proxy for the actual service

3 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (3) –Non-software example (1) Toll-free numbers –Client dials the “800” area code just like they would for a real area code –Proxy records billing information and connects to actual area code

4 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (4) –Non-software example (2) Checks –Check is a proxy for the actual funds in the bank

5 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (5) –Abstract Description Object Proxy Pattern Notice the “is-a” and “has-a” relations again.

6 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (6) –Abstract Description Sequence Diagram (typical proxy application)

7 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (7) –Consequences Isolates RealSubject from client –Forces controllable indirection Costs indirection –True for all delegation models May require duplicate information in Proxy and RealSubject –Must support same “properties” –These must be supported even before instantiation of RealSubject

8 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (8) –Consequences Creates second class dependent on Subject interface –Unavoidable in this pattern Client may need to be aware of Proxy –For example, extra failure modes –Example: java.rmi.MarshalException in RMI

9 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (9) –Implementation Issues Three basic types of proxies 1. Remote Proxy »Proxy used to “hide” the location of RealSubject »Example: RMI implementation 2. Virtual Proxy »Performs optimizations »Example: Image rendering in HTML

10 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (10) –Implementation Issues Three basic types of proxies 3. Housekeeping Proxy »Performs additional maintenance duties »Example: Cache Proxy »Example: Protection Proxy

11 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (11) –Implementation Issues Proxy can be written independent of RealSubject –Use Subject interface in definition of Proxy –Difficult (or impossible) if Proxy stores redundant information

12 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (12) –Common Variations Firewall Proxy (a protection proxy) –Protects targets from bad clients (or vice versa) Synchronization Proxy (a housekeeping proxy) –Provides multiple accesses to a target object Smart Reference Proxy (a housekeeping proxy) –Provides additional actions whenever a target object is referenced Copy-on-Write Proxy (a virtual proxy) –Defers cloning an object until required

13 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (13) –Java API Usage java.rmi library “Remote Method Invocation” Allows objects in separate virtual machines to be used as if local (language specific) Uses “stub and skeleton” to handle communication


Download ppt "Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (1) –A structural design pattern."

Similar presentations


Ads by Google