More Related Content
Similar to Proxy pattern (20)
More from Shakil Ahmed (18)
Proxy pattern
- 3. Motivation
Reduce the full cost of creation and
initialization unless we actually need that.
Copyright © Astha
- 5. Applicability
A 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
- 8. Participants
Proxy (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
- 9. Participants
◦ 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
- 10. Participants
Subject (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
- 12. Consequences
A 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
- 13. Assignment
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.
Copyright © Astha