Proxy Pattern


Definition 1

A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. In short, a proxy is a wrapper or agent object that is being called by the client to access the real serving object behind the scenes.

Structure 2


  • maintains a reference that lets the proxy access the real subject. Proxy may refer to a Subject if the RealSubject and Subject interfaces are the same.
  • 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.
  • 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. For example, the ImageProxy from the Motivation caches the real image’s extent.
    • protection proxies check that the caller has the access
      permissions required to perform a request.


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


  • defines the real object that the proxy represents.

Example Code


Real Implementations

Remoter service invocation on Android 3 on Android


One thought on “Proxy Pattern

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s