Proxy Pattern In Proxy pattern a class represents

  • Slides: 15
Download presentation
Proxy Pattern

Proxy Pattern

 • In Proxy pattern, a class represents functionality of another class. This type

• In Proxy pattern, a class represents functionality of another class. This type of design pattern comes under structural pattern. • In Proxy pattern, we create object having original object to interface its functionality to outer world

Intent Provide a surrogate or placeholder for another object to control access to it.

Intent Provide a surrogate or placeholder for another object to control access to it. Also Known As Surrogate

Applicability ØA remote proxy provides a local representative for an object in a different

Applicability ØA remote proxy provides a local representative for an object in a different address space. NEXTSTEP [Add 94] uses the class NXProxy for this purpose. Øvirtual proxy creates expensive objects on demand. The Image. Proxy described in the Motivation is an example of such a proxy.

Participants • Proxy (Image. Proxy) o maintains a reference that lets the proxy access

Participants • Proxy (Image. Proxy) o maintains a reference that lets the proxy access the real subject. Proxy may refer to a Subject if the Real. Subject and Subject interfaces are the same. • Subject (Graphic) • Real. Subject (Image)

Collaborations Proxy forwards requests to Real. Subject when appropriate, depending on the kind of

Collaborations Proxy forwards requests to Real. Subject when appropriate, depending on the kind of proxy.

Consequences The Proxy pattern introduces a level of indirection when accessing an object. The

Consequences The Proxy pattern introduces a level of indirection when accessing an object. The additional indirection has many uses, depending on the kind of proxy: 1. A remote proxy can hide the fact that an object resides in a different address space. 2. A virtual proxy can perform optimizations such as creating an object on demand. 3. Both protection proxies and smart references allow additional housekeeping tasks when an object is accessed.

Proxy (Non software example) Provide a surrogate or placeholder for another object to control

Proxy (Non software example) Provide a surrogate or placeholder for another object to control access to it.

 • Implementation • We're going to create a Image interface and concrete classes

• Implementation • We're going to create a Image interface and concrete classes implementing the Image interface. Proxy. Image is a a proxy class to reduce memory footprint of Real. Image object loading. Proxy. Pattern. Demo, our demo class will use Proxy. Image to get a Image object to load and display as it needs.