advertisement

Proxy design pattern (Class Ambassador)

100 %
0 %
advertisement
Information about Proxy design pattern (Class Ambassador)
Technology

Published on February 19, 2014

Author: SameerRathoud

Source: slideshare.net

Description

This presentation provide information to understand proxy design pattern, it’s structure and it’s implementation.
advertisement

Proxy Design Pattern Class Ambassador Sameer Singh Rathoud

About presentation This presentation provide information to understand proxy design pattern, it’s structure and it’s implementation. I have tried my best to explain the concept in very simple language. The programming language used for implementation is c#. But any one from different programming background can easily understand the implementation.

Definition Provide a surrogate or placeholder for another object to control access to it. A proxy, in its most general form, is a class functioning as an interface to something else. http://en.wikipedia.org/wiki/Proxy_pattern Proxy pattern is a structural design pattern.

Motivation and Intent You need to support resource-hungry objects, and you do not want to instantiate such objects unless and until they are actually requested by the client. • Provide a surrogate or placeholder for another object to control access to it. • Use an extra level of indirection to support distributed, controlled, or intelligent access. • Add a wrapper and delegation to protect the real component from undue complexity.

Structure << interface >> Subject Client Operation () Inheritance Real Subject Operation () Proxy Operation () realSubject.Operation()

Participants in structure • Subject (interface): is a interface implemented by real subject, but proxy should also implement this interface, so that where ever real subject is used, there proxy can be used. • Proxy: • Maintain the reference of the real subject, so that it can be accessed through proxy. • Implements the same interface implemented by real subject, so that it can be used as substitute of real subject. • Control access to the real subject and responsible for its creation and deletion. • Can have other responsibilities depends on the proxy. • Real Subject: The real logic that the proxy represents. • Client: The user of the proxy design pattern.

Collaborations • Proxy forwards requests to real subject when appropriate, depending on the kind of proxy. Proxy Client Real Subject new Proxy () Operation() new RealSubject () Operation()

Types • 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: creates expensive objects on demand. • Protection proxies: controls access to the original object. Protection proxies are useful when objects should have different access rights.

Implementation (C#) Subject (Interface) abstract class Subject { public abstract void Operation(); } Here “Subject” is an abstract class with an abstract method “Operation”. Now all the concrete classes implementing this abstract class will override “Operation” method. << interface >> Subject + Operation ()

Implementation (C#) Here the concrete classes “Proxy” and “RealSubject” are implementing ConcreteSubject: RealSubject and Proxy abstract class “Subject” and these concrete classes are overriding class RealSubject : Subject “Operation” method (giving class { public override void Operation() specific definition of function) of { “Subject” class. Additionally “Proxy” Console.WriteLine("Called RealSubject.Operation()"); contains the reference of “RealSubject” } class. } << interface >> Subject class Proxy : Subject { private RealSubject realSubject; public override void Operation() { if (realSubject == null) { realSubject = new RealSubject(); } realSubject.Operation(); } } + Operation () RealSubject Proxy - realSubject (RealSubject) Operation () Operation ()

Implementation (C#) Client class Client { static void Main(string[] args) { Proxy proxy = new Proxy(); proxy.Operation(); } } For using proxy pattern the client has to create a “Proxy” reference and this reference is used to call the “Operation”.

Example A smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed. Typical uses include • counting the number of references to the real object so that it can be freed automatically when there are no more references. • loading a persistent object into memory when it's first referenced. • checking that the real object is locked before it's accessed to ensure that no other object can change it. A check or an bank draft is another example of proxy pattern. Here check represents the fund in the account. A check can be used for making purchases and it is controlling the fund in the account.

End of Presentation . . .

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

Proxy pattern - Wikipedia, the free encyclopedia

The following Java example illustrates the "virtual proxy" pattern. The ProxyImage class is used to access ... Proxy Design Pattern; Proxy pattern C++ ...
Read more

Proxy Design Pattern - Design Patterns & Refactoring

Proxy design pattern. The Proxy provides a surrogate or place holder to provide access to ... Flyweight Design Pattern; Private Class Data; Proxy Design ...
Read more

Proxy Design Pattern - CodeProject - For those who code

Proxy Design Pattern clearly explained with ... The ISubject interface is the interface that both the Proxy class and the RealSubject class ...
Read more

Proxy .NET Design Pattern in C# and VB - dofactory.com

/// MainApp startup class for Structural /// Proxy Design Pattern. /// Read more

Proxy Design Pattern in C++: Before and after

Proxy design pattern С++ example. ... Private Class Data; Proxy Design Pattern ; Behavioral patterns; Design Patterns Book. Design Patterns. Creational ...
Read more

Proxy Pattern | Object Oriented Design

Proxy, Proxy Pattern, Design Patterns, ... Virtual Proxy, Proxy Pattern Example, Service Proxy, Java, ... The participants classes in the proxy pattern are:
Read more

Proxy Design Pattern Using C# - C# Corner - Developers and ...

This article explaiins the Proxy Design Pattern. ... The client application must use a proxy class to get ... Adapter vs Mediator vs Bridge vs Proxy patterns
Read more

Proxy Design Pattern - CodeProject

Thus the Proxy class will indirectly lead to call of Actual class. Proxy: ... A Proxy Design Pattern has various variations that include: Virtual Proxy.
Read more