1 / 14

Proxy Design Pattern

Proxy Design Pattern. By:Diksha Agarwal. Definition. Provide a surrogate or placeholder for another object to control access to it. Intent.

shaw
Télécharger la présentation

Proxy Design Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Proxy Design Pattern By:Diksha Agarwal

  2. Definition • Provide a surrogate or placeholder for another object to control access to it.

  3. Intent • Proxy pattern describe how to provide a level of indirection to an object, and the implementations of the proxy object keep a reference to another object to which they forwards requests. • Proxy pattern composes an object and provides an identical interface to clients. • Its intent is to provide a stand-in for a subject when it's inconvenient or undesirable to access the subject directly because, for example, it lives on a remote machine or has restricted access.

  4. Motivation • One reason for controlling access to an object is to defer the full cost of its creation and initialization until we actually need to use it.

  5. Applicability • A proxy is applicable whenever there is a need for a more versatile or sophisticated reference to an object than a simple pointer. A remote proxy provides a local representation for an object in a different address space. It provides an interface identical to the subjects, controls access to the real subject and also may be responsible for creating and deleting it. A remote proxy is responsible for encoding a request and its arguments and for sending the encoded request to the real subject in a different address space.

  6. Structure

  7. Participation • Proxy - Maintains a reference that lets the proxy access the real subject. Proxy may refer to a Subject if the RealSubject and Subject interfaces are the same. - Provides an interface identical to Subject's so that a proxy can by substituted for real subject. - Controls access to the real subject and may be responsible for creating and deleting it. other responsibilities depend on the kind of proxy. • Subject - Defines the common interface for RealSubject and Proxy so that a Proxy can be used anywhere a RealSubject is expected. • RealSubject - Defines the real object that the proxy represents.

  8. Example- Payment By Cheque • The Problem: A person has cash in his bank account but does not carry cash with him. • The Solution: The proxy Design Pattern.

  9. Example Contd.. • The cheque acts as a proxy for the funds in the account. • The funds are the real subjects. • The client asks for payment through the Cheque. • The proxy allows the cheque to act as if it were actual funds.

  10. Related Patterns: • Adapter provides a different interface to the object it adapts, while proxy provides the same interface as the subject. • Decorators can have similar implementations as proxies but they have a different purpose; A decorator adds one or more responsibilities to an object, whereas proxy controls access to an object.

  11. Costs Incurred… • There are no real costs associated with the proxy pattern. • Proxy allows for the saving of run time costs by deferring processing of objects until it is actually required.

  12. Conclusion: • Proxy creates a level of indirection that can have multiple purposes. • The major uses of this design pattern are: • The remote proxy hides the fact that the object is in different object space. • A virtual proxy can create optimizations such as creating an object on demand. • An access proxy allows additional housekeeping tasks when an object is accessed.

  13. References: • http://www.inf.bme.hu/ooret/1999osz/DesignPatterns/Proxy4/ • http://web.media.mit.edu/~tpminka/patterns/Proxy.html • http://selab.korea.ac.kr/selab/courses/GoF-patterns/proxy.htm#Structure • http://pages.cpsc.ucalgary.ca/~heinrich/443/TheFlyweightandProxyDesignPatterns.ppt

More Related