SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
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 . . .

Mais conteúdo relacionado

Mais procurados

Presentation on Template Method Design Pattern
Presentation on Template Method Design PatternPresentation on Template Method Design Pattern
Presentation on Template Method Design Pattern
Asif Tayef
 

Mais procurados (20)

Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Presentation on Template Method Design Pattern
Presentation on Template Method Design PatternPresentation on Template Method Design Pattern
Presentation on Template Method Design Pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Memento pattern
Memento patternMemento pattern
Memento pattern
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
One Monad to Rule Them All
One Monad to Rule Them AllOne Monad to Rule Them All
One Monad to Rule Them All
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
 
Struts
StrutsStruts
Struts
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
Design Pattern - Singleton Pattern
Design Pattern - Singleton PatternDesign Pattern - Singleton Pattern
Design Pattern - Singleton Pattern
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 

Semelhante a Proxy design pattern (Class Ambassador)

Gang of four Proxy Design Pattern
 Gang of four Proxy Design Pattern Gang of four Proxy Design Pattern
Gang of four Proxy Design Pattern
Mainak Goswami
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
LearningTech
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
LearningTech
 
DesignPatternScard.pdf
DesignPatternScard.pdfDesignPatternScard.pdf
DesignPatternScard.pdf
JTLai1
 
Factory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilitiesFactory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilities
babak danyal
 

Semelhante a Proxy design pattern (Class Ambassador) (20)

Gang of four Proxy Design Pattern
 Gang of four Proxy Design Pattern Gang of four Proxy Design Pattern
Gang of four Proxy Design Pattern
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
 
1. Mini seminar intro
1. Mini seminar intro1. Mini seminar intro
1. Mini seminar intro
 
DesignPatternScard.pdf
DesignPatternScard.pdfDesignPatternScard.pdf
DesignPatternScard.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Go f designpatterns 130116024923-phpapp02
Go f designpatterns 130116024923-phpapp02Go f designpatterns 130116024923-phpapp02
Go f designpatterns 130116024923-phpapp02
 
Factory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilitiesFactory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilities
 
Proxy Design Pattern
Proxy Design PatternProxy Design Pattern
Proxy Design Pattern
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
 
Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014Dependency injection Drupal Camp Wrocław 2014
Dependency injection Drupal Camp Wrocław 2014
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
C# Advanced L07-Design Patterns
C# Advanced L07-Design PatternsC# Advanced L07-Design Patterns
C# Advanced L07-Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
INTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMINGINTRODUCTION TO CLIENT SIDE PROGRAMMING
INTRODUCTION TO CLIENT SIDE PROGRAMMING
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
How to design an application correctly ?
How to design an application correctly ?How to design an application correctly ?
How to design an application correctly ?
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 

Mais de Sameer Rathoud

Mais de Sameer Rathoud (8)

Platformonomics
PlatformonomicsPlatformonomics
Platformonomics
 
AreWePreparedForIoT
AreWePreparedForIoTAreWePreparedForIoT
AreWePreparedForIoT
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())
 
Builder Design Pattern (Generic Construction -Different Representation)
Builder Design Pattern (Generic Construction -Different Representation)Builder Design Pattern (Generic Construction -Different Representation)
Builder Design Pattern (Generic Construction -Different Representation)
 
Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)
 
Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Proxy design pattern (Class Ambassador)

  • 1. Proxy Design Pattern Class Ambassador Sameer Singh Rathoud
  • 2. 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.
  • 3. 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.
  • 4. 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.
  • 5. Structure << interface >> Subject Client Operation () Inheritance Real Subject Operation () Proxy Operation () realSubject.Operation()
  • 6. 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.
  • 7. 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()
  • 8. 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.
  • 9. 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 ()
  • 10. 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 ()
  • 11. 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”.
  • 12. 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.