proxy pattern
DESCRIPTION
Proxy patternTRANSCRIPT
Design PatternDesign Pattern
Proxy PatternA Structural Pattern
Presented by: Hasnaeen Rizvi Rahman
Copyright © Astha
IntentIntentProvide a surrogate or
placeholder for another object to control access to it.
Copyright © Astha
MotivationMotivationReduce the full cost of creation and
initialization unless we actually need that.
Copyright © Astha
Copyright © Astha
Document EditorDocument Editor
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
StructureStructure
Copyright © Astha
Object DiagramObject Diagram
Copyright © Astha
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
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
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
CollaborationsCollaborationsProxy forwards requests to
RealSubject when appropriate, depending on the kind of proxy.
Copyright © Astha
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
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.