13
Design Pattern Design Pattern Proxy Pattern A Structural Pattern Presented by: Hasnaeen Rizvi Rahman Copyright © Astha

Proxy pattern

Embed Size (px)

DESCRIPTION

Proxy pattern

Citation preview

Page 1: Proxy pattern

Design PatternDesign Pattern

Proxy PatternA Structural Pattern

Presented by: Hasnaeen Rizvi Rahman

Copyright © Astha

Page 2: Proxy pattern

IntentIntentProvide a surrogate or

placeholder for another object to control access to it.

Copyright © Astha

Page 3: Proxy pattern

MotivationMotivationReduce the full cost of creation and

initialization unless we actually need that.

Copyright © Astha

Page 4: Proxy pattern

Copyright © Astha

Document EditorDocument Editor

Page 5: Proxy pattern

ApplicabilityApplicabilityA remote proxy provides a local

representative for an object in a different address space.

A virtual proxy creates expensive objects on demand.

A protection proxy controls access to the original object. Protection proxies are useful when objects should have different access rights.

A smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed.

Copyright © Astha

Page 6: Proxy pattern

StructureStructure

Copyright © Astha

Page 7: Proxy pattern

Object DiagramObject Diagram

Copyright © Astha

Page 8: Proxy pattern

ParticipantsParticipantsProxy (ImageProxy)

◦Maintains a reference that lets the proxy access the real subject.

◦Provides an interface identical to Subject's so that a proxy can by substituted for the real subject.

◦Controls access to the real subject and may be responsible for creating and deleting it.

Copyright © Astha

Page 9: Proxy pattern

ParticipantsParticipants

◦Other responsibilities depend on the kind of proxy. Remote proxies. are responsible for

encoding a request and its arguments and for sending the encoded request to the real subject in a different address space.

Virtual proxies may cache additional information about the real subject so that they can postpone accessing it.

Protection proxies check that the caller has the access permissions required to perform a request.

Copyright © Astha

Page 10: Proxy pattern

ParticipantsParticipantsSubject (Graphic)

◦Defines the common interface for RealSubject and Proxy so that a Proxy can be used anywhere a RealSubject is expected.

RealSubject (Image)◦Defines the real object that the

proxy represents.

Copyright © Astha

Page 11: Proxy pattern

CollaborationsCollaborationsProxy forwards requests to

RealSubject when appropriate, depending on the kind of proxy.

Copyright © Astha

Page 12: Proxy pattern

ConsequencesConsequencesA remote proxy can hide the fact

that an object resides in a different address space.

A virtual proxy can perform optimizations such as creating an object on demand.

Both protection proxies and smart references allow additional housekeeping tasks when an object is accessed.

Copyright © Astha

Page 13: Proxy pattern

AssignmentAssignment

Copyright © Astha

Some applications allow you to search local-help before searching on-line help. Local help is naturally faster since it resides on your hard drive. On-line help on the other hand is more complete and up-to-date, has undergone greater error-checking based on more users' feedback, refers to more sources and is more up-to-date. Local help is therefore like a proxy for the on-line help. Most times the user will be able to find answers in local-help, but for those really tough problems in specialized situations, on-line help comes to the rescue.

Solve the problem by using proxy design pattern.