{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Background image of page 1

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

View Full Document Right Arrow Icon
Problem You need to control access to an object
Background image of page 2
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
Background image of page 3

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

View Full Document Right Arrow Icon
Solution +Request() «interface» Subject Client +Request() +realSubject Proxy +Request() Real Subject // do pre-processing here realSubject->Request(); // do post-processing here
Background image of page 4
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
Background image of page 5

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

View Full Document Right Arrow Icon
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
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}