Proxy Pattern - Virtual House Designer

- 18.40

In computer programming, the proxy pattern is a software design pattern.

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.

A well-known example of the proxy pattern is a reference counting pointer object.

In situations where multiple copies of a complex object must exist, the proxy pattern can be adapted to incorporate the flyweight pattern in order to reduce the application's memory footprint. Typically, one instance of the complex object and multiple proxy objects are created, all of which contain a reference to the single original complex object. Any operations performed on the proxies are forwarded to the original object. Once all instances of the proxy are out of scope, the complex object's memory may be deallocated.

And Cute Virtual House Decoration Online Free - bedroom furniture ...



Usage

The proxy design pattern allows you to provide an interface to other objects by creating a wrapper class as the proxy. The wrapper class, which is the proxy, can add additional functionality to the object of interest without changing the object's code. Below are some of the common examples in which the proxy pattern is used,

  • Adding security access to an existing object. The proxy will determine if the client can access the object of interest.
  • Simplifying the API of complex objects. The proxy can provide a simple API so that the client code does not have to deal with the complexity of the object of interest.
  • Providing interface for remote resources, such as web service or REST resources.
  • Coordinating expensive operations on remote resources by asking the remote resources to start the operation as soon as possible before accessing the resources.
  • Adding a thread-safe feature to an existing class without changing the existing class's code.

In short, the proxy is the object that is being called by the client to access the real object behind the scenes.



Possible Usage Scenarios

Remote Proxy - Represents an object locally which belongs to a different address space. Think of an ATM implementation, it will hold proxy objects for bank information that exists in the remote server.

Virtual Proxy - In place of a complex or heavy object, use a skeleton representation. When an underlying image is huge in size, just represent it using a virtual proxy object and on demand load the real object. You know that the real object is expensive in terms of instantiation and so without the real need we are not going to use the real object. Until the need arises we will use the virtual proxy.

Protection Proxy - Are you working on an MNC? If so, we might be well aware of the proxy server that provides us internet by restricting access to some sort of websites like public e-mail, social networking, data storage etc. The management feels that, it is better to block some content and provide only work related web pages. Proxy server does that job. This is a type of proxy design pattern.

Inspiring Build A Virtual House Design Online Free For Office ...


Example

C++

C#

Output

  Sorry, the driver is too young to drive.  Car has been driven!  

Notes:

  • A proxy may hide information about the real object to the client.
  • A proxy may perform optimization like on demand loading.
  • A proxy may do additional house-keeping job like audit tasks.
  • Proxy design pattern is also known as surrogate design pattern.

Java

The following Java example illustrates the "virtual proxy" pattern. The ProxyImage class is used to access a remote method.

The example creates first an interface against which the pattern creates the classes. This interface contains only one method to display the image, called displayImage(), that has to be coded by all classes implementing it.

The proxy class ProxyImage is running on another system than the real image class itself and can represent the real image RealImage over there. The image information is accessed from the disk. Using the proxy pattern, the code of the ProxyImage avoids multiple loading of the image, accessing it from the other system in a memory-saving manner. It should be noted, however, that the lazy loading demonstrated in this example is not part of the proxy pattern, but is merely an advantage made possible by the use of the proxy.

The program's output is:

  Loading   HiRes_10MB_Photo1  Displaying HiRes_10MB_Photo1  Displaying HiRes_10MB_Photo1  Loading   HiRes_10MB_Photo2  Displaying HiRes_10MB_Photo2  Displaying HiRes_10MB_Photo2  Displaying HiRes_10MB_Photo1  
Virtual | Sonshine House


See also

  • Composite pattern
  • Decorator pattern
  • Lazy initialization
Virtual Bedroom Designer - House Interior And Exterior


References

Array

External links

  • Proxy pattern in UML and in LePUS3 (a formal modelling language)
  • Take control with the Proxy design pattern by David Geary, JavaWorld.com
  • PerfectJPattern Open Source Project, Provides componentized implementation of the Proxy Pattern in Java
  • Adapter vs. Proxy vs. Facade Pattern Comparison
  • Proxy Design Pattern
  • Proxy pattern C++ implementation example
  • Proxy pattern description from the Portland Pattern Repository


Interesting Informations

Looking products related to this topic, find out at Amazon.com

Source of the article : here





EmoticonEmoticon

 

Start typing and press Enter to search