Proxy - Proxy Design Pattern Source: Design Patterns...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Proxy Design Pattern Source: Design Patterns Elements of Reusable Object- Oriented Software; Gamma, et. al. Problem You need to control access to an object Solution Create a Proxy object that implements the same interface as the real object The Proxy object (usually) contains a reference to the real object Clients are given a reference to the Proxy, not the real object All client operations on the object pass through the Proxy, allowing the Proxy to perform additional processing Client Proxy Real Object Solution +Request() interface Subject Client +Request() +realSubject Proxy +Request() Real Subject // do pre-processing here realSubject->Request(); // do post-processing here Consequences Provides an additional level of indirection between client and object that may be used to insert arbitrary services Proxies are invisible to the client, so introducing proxies does not affect client code Known Uses: Java Collections Read-only Collections Wrap collection object in a proxy that only allows read-only operations to be invoked on the collection All other operations throw exceptions List Collections.unmodifiableList(List list); Returns read-only List proxy Synchronized Collections Wrap collection object in a proxy that ensures only one thread at a time is allowed to access the collection Proxy acquires lock before calling a method, and releases lock after the method completes List Collections.synchronizedList(List list); Returns a synchronized List proxy Known Uses: Distributed Objects...
View Full Document

Page1 / 14

Proxy - Proxy Design Pattern Source: Design Patterns...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online