Design Pattern: PROXY - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Design Pattern: PROXY

Description:

A Proxy is a surrogate or a placeholder for another object to control access to ... Sometimes the Proxy pattern is known as an Ambassador pattern when dealing with ... – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 14
Provided by: weite7
Category:
Tags: proxy | design | pattern

less

Transcript and Presenter's Notes

Title: Design Pattern: PROXY


1
Design Pattern PROXY
  • Wei-Tek Tsai
  • Department of Computer Science and Engineering
  • Arizona State University
  • Tempe, AZ

2
Definition
  • A Proxy is a surrogate or a placeholder for
    another object to control access to the real
    objects.
  • Sometimes the Proxy pattern is known as an
    Ambassador pattern when dealing with distributed
    objects.
  • Applicability The Proxy pattern is applicable
    when there is a need for sophistication in a
    reference to an object. There is added function
    between a client and the intended subject object.

3
Proxy Structure
4
Proxy Pattern More Structure
  • The Subject defines the common interface for the
    RealSubject and Proxy.
  • The Proxy can be used any place a RealSubject is
    expected.
  • The RealSubject defines the real object that the
    Proxy represents.

5
Proxy Document Editor Example
6
Proxy Pattern Properties
  • Maintains the ability to access the real
    object, while screening requests for direct
    manipulation of the object.
  • Provides an identical interface to the Subject
    so that it can be substituted for the Subject in
    any instance.
  • Control access to the Subject, even managing
    it.
  • Has other responsibilities defined by the type
    of Proxy
  • Remote Proxies
  • Virtual Proxies
  • Protection Proxies
  • Smart Reference Proxies

7
Remote Proxies
  • Are responsible for encoding requests (with its
    accompanying arguments) to forward to its
    corresponding real object, which is found in
    another address space (Remote or Distributed
    Object).
  • This Proxy is an Ambassador to a distributed
    object.
  • This Proxy hides the fact from the user that the
    object is distributed.

8
Virtual Proxies
  • Cache information about the real object, so that
    they only access the object when it is absolutely
    necessary.
  • This Proxy is used to access expensive objects,
    such as objects high in storage, access time, or
    another limit resource, created on demand.
  • Example ImageProxy

9
Protection Proxies
  • Protect access the the original object.
  • This means that screen users to access the real
    object or only allow access to a limited public
    interface.
  • While the real object may have a private
    interface is then a subset of the real interface.
  • Example KernelProxies in the Choices Operating
    System that provide a protected access to
    operating system objects.

10
Smart Reference Proxy
  • A Smart Reference Proxy is a replacement for a
    bare pointer
  • A Smart Reference Proxy performs additional
    actions when an object is accessed
  • Count the number of references to the real object
    so that it can be automatically freed when there
    are no more references.
  • Create a transient representation for a
    persistent object that is loading the object into
    memory.
  • Copy on write, that is normally just increment
    the reference count when asked to copy the
    Subject, only doing the actual copy when the
    client requests an operation that modifies the
    Subject.
  • Check for locking before forwarding an access
    request.

11
Proxy Pattern Participants Collaborations
  • Participants
  • Proxy
  • Subject
  • Defines the common interface for ConcreteSubject
    and Proxy so that Proxy can be used anywhere a
    ConcreteSubject is expected
  • ConcreteSubject
  • Defines the real object that the Proxy represents
  • Collaborations
  • The Proxy forwards all requests to the
    ConcreteSubject. But before doing so, the Proxy
    performs additional actions depending on the kind
    of Proxy.

12
Proxy Pattern Consequences
  • A Proxy pattern introduces a level of indirection
    when accessing an object.
  • A Remote Proxy can hide the fact that an object
    resides in a different address space.
  • A Virtual Proxy can perform optimizations like
    creating an object on demand.
  • Both Protected Proxies and Smart References allow
    additional housekeeping tasks when an object is
    accessed.

13
Proxy Pattern Distinguishing Aspects
  • The Proxy is a stand in for a Subject when it
    is inconvenient or undesirable to access the
    Subject directly, as it may be on a remote
    machine, has restricted access, or is persistent.
  • The Proxy maintains a reference to the Subject
    object and forwards all requests to the Concrete
    or RealSubject, but will perform additional
    actions before forwarding the request.
  • The Proxy provides the same interface, or a
    subset, as the original object.
  • The Proxy pattern models a one to one
    relationship and this relationship is a static
    relationship.
Write a Comment
User Comments (0)
About PowerShow.com