SlideShare a Scribd company logo
1 of 33
Proxy Design Pattern Anjan Kumar BollamSrikanth Gorlla Design Patterns Summer 09
Example – Financial proxy 6/15/09 2
Questions on Proxy design pattern What is the intent of Proxy Design Pattern? What is the motivation of Proxy Design Pattern? If a Proxy is used to instantiate an object only when it is absolutely needed, does the Proxy simplify code? How to handle multiple copies of the Complex Object using Proxy? What are the advantages of using Proxy? What are the other related patterns for Proxy? When do we use Proxy Design Pattern? 6/15/09 3
Intent Provide a surrogate or placeholder for another object to control access to it. ,[object Object]
Protects real component from undue complexityAlso Known as : ,[object Object],6/15/09 4
Motivation Creating objects even though they are not required may be expensive in terms of time or computer resource. ,[object Object]
Proxy also allows us to vary how and where an object is accessed.
Proxy creates each expensive object only when required.When to postpone object creation? ,[object Object]
When you need to represent an object that is complex or time consuming to create with a simpler one.6/15/09 5
Motivation - Example Document Editor ,[object Object]
Loading of Graphical images takes time.
This may slow down the opening of the document.
But what to put instead of the actual object while initializing?We can use a PROXY 6/15/09 6
Motivation - Example Image Proxy ,[object Object]
Takes care of instantiating the real object when required by invoking the draw() function.
Forwards the subsequent requests directly to the image
Creates the real image only when the document editor asks it to 6/15/09 7
Applicability Proxy is applicable whenever there is a need for more versatile or sophisticated reference to an object than simple pointer. Key Words: Versatile or sophisticated ,[object Object],6/15/09 8
Applicable Situations A remote proxy provides a local representative for an object in a different address space A virtual proxy creates expensive objects on demand. A protection proxy controls access to the original object. A smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed. 6/15/09 9
Smart References Typical uses include  ,[object Object]
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.6/15/09 10
Structure – Class Diagram 6/15/09 11 Provide a surrogate or placeholder for another object to control access to it.
Structure – Object Diagram 6/15/09 12
Participants 6/15/09 13 The three participants are: ,[object Object]
Subject
Real Subject,[object Object]
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. ,[object Object],[object Object],[object Object]
Collaborations 6/15/09 18 Proxy forwards requests to Real Subject when appropriate, depending on the kind of proxy.
Consequences The Proxy pattern introduces a level of indirection when accessing an object. This additional indirection has many uses. ,[object Object]
A virtual proxy can perform optimizations such as creating an object on demand.
Both protection proxies and smart references allow additional housekeeping tasks when an object is accessed. 6/15/09 19

More Related Content

What's hot

Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
11prasoon
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
Aman Jain
 

What's hot (20)

Proxy Design Patterns
Proxy Design PatternsProxy Design Patterns
Proxy Design Patterns
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Design Pattern - Singleton Pattern
Design Pattern - Singleton PatternDesign Pattern - Singleton Pattern
Design Pattern - Singleton Pattern
 
Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Visitor Pattern
Visitor PatternVisitor Pattern
Visitor Pattern
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Design pattern
Design patternDesign pattern
Design pattern
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 
Interaction Modeling
Interaction ModelingInteraction Modeling
Interaction Modeling
 
Use case Diagram
Use case Diagram Use case Diagram
Use case Diagram
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 

Viewers also liked

Template method pattern example
Template method pattern exampleTemplate method pattern example
Template method pattern example
Guo Albert
 
Software Engineering ppt
Software Engineering pptSoftware Engineering ppt
Software Engineering ppt
shruths2890
 

Viewers also liked (15)

Software design patterns ppt
Software design patterns pptSoftware design patterns ppt
Software design patterns ppt
 
The Decorator Pattern
The Decorator PatternThe Decorator Pattern
The Decorator Pattern
 
Design Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator PatternDesign Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator Pattern
 
Template Method Design Pattern
Template Method Design PatternTemplate Method Design Pattern
Template Method Design Pattern
 
Template method pattern example
Template method pattern exampleTemplate method pattern example
Template method pattern example
 
Factory Pattern
Factory PatternFactory Pattern
Factory Pattern
 
Bridge pattern for Dummies
Bridge pattern for DummiesBridge pattern for Dummies
Bridge pattern for Dummies
 
Soa Overview
Soa OverviewSoa Overview
Soa Overview
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Software Design Patterns - Selecting the right design pattern
Software Design Patterns - Selecting the right design patternSoftware Design Patterns - Selecting the right design pattern
Software Design Patterns - Selecting the right design pattern
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
 
Software Engineering ppt
Software Engineering pptSoftware Engineering ppt
Software Engineering ppt
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 

Similar to Proxy Design Pattern

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
 
Tutor-marked assignment TMA 03 Printable page generated Saturd.docx
Tutor-marked assignment TMA 03 Printable page generated Saturd.docxTutor-marked assignment TMA 03 Printable page generated Saturd.docx
Tutor-marked assignment TMA 03 Printable page generated Saturd.docx
juliennehar
 
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon
 

Similar to Proxy Design Pattern (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 Patterns - Part 2 of 2
Design Patterns - Part 2 of 2Design Patterns - Part 2 of 2
Design Patterns - Part 2 of 2
 
Introduction-to-Design-Patternsssss.pptx
Introduction-to-Design-Patternsssss.pptxIntroduction-to-Design-Patternsssss.pptx
Introduction-to-Design-Patternsssss.pptx
 
Chrome & Webkit overview
Chrome & Webkit overviewChrome & Webkit overview
Chrome & Webkit overview
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
JAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp conceptsJAVA design patterns and Basic OOp concepts
JAVA design patterns and Basic OOp concepts
 
Design patterns through java
Design patterns through javaDesign patterns through java
Design patterns through java
 
Opendelight reference-guide
Opendelight reference-guideOpendelight reference-guide
Opendelight reference-guide
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
 
Machine Learning Use Case - Agriculture
Machine Learning Use Case - AgricultureMachine Learning Use Case - Agriculture
Machine Learning Use Case - Agriculture
 
SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11
 
RICOH THETA x IoT Developers Contest : Cloud API Seminar
 RICOH THETA x IoT Developers Contest : Cloud API Seminar RICOH THETA x IoT Developers Contest : Cloud API Seminar
RICOH THETA x IoT Developers Contest : Cloud API Seminar
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
 
Understanding AngularJS HTML5 DataServices
Understanding AngularJS HTML5 DataServicesUnderstanding AngularJS HTML5 DataServices
Understanding AngularJS HTML5 DataServices
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
Akka.Net & .Net Core - .Net Inside 4° MeetUp
Akka.Net & .Net Core - .Net Inside 4° MeetUpAkka.Net & .Net Core - .Net Inside 4° MeetUp
Akka.Net & .Net Core - .Net Inside 4° MeetUp
 
Android architecture
Android architecture Android architecture
Android architecture
 
Tutor-marked assignment TMA 03 Printable page generated Saturd.docx
Tutor-marked assignment TMA 03 Printable page generated Saturd.docxTutor-marked assignment TMA 03 Printable page generated Saturd.docx
Tutor-marked assignment TMA 03 Printable page generated Saturd.docx
 
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
 

Recently uploaded

一比一原版格林威治大学毕业证成绩单如何办理
一比一原版格林威治大学毕业证成绩单如何办理一比一原版格林威治大学毕业证成绩单如何办理
一比一原版格林威治大学毕业证成绩单如何办理
cyebo
 
一比一原版谢菲尔德大学毕业证成绩单如何办理
一比一原版谢菲尔德大学毕业证成绩单如何办理一比一原版谢菲尔德大学毕业证成绩单如何办理
一比一原版谢菲尔德大学毕业证成绩单如何办理
cyebo
 
Knowing, Understanding and Planning Cities- Role and Relevance Physical Plan...
Knowing, Understanding and Planning Cities- Role and Relevance  Physical Plan...Knowing, Understanding and Planning Cities- Role and Relevance  Physical Plan...
Knowing, Understanding and Planning Cities- Role and Relevance Physical Plan...
JIT KUMAR GUPTA
 
Heuristic Evaluation of System & Application
Heuristic Evaluation of System & ApplicationHeuristic Evaluation of System & Application
Heuristic Evaluation of System & Application
Jaime Brown
 

Recently uploaded (20)

Design Portofolios - Licensed Architect / BIM Specialist
Design Portofolios - Licensed Architect / BIM SpecialistDesign Portofolios - Licensed Architect / BIM Specialist
Design Portofolios - Licensed Architect / BIM Specialist
 
spColumn-Manual design column by spcolumn software.pdf
spColumn-Manual design column by spcolumn software.pdfspColumn-Manual design column by spcolumn software.pdf
spColumn-Manual design column by spcolumn software.pdf
 
BIT Khushi gandhi project.pdf graphic design
BIT Khushi gandhi project.pdf graphic designBIT Khushi gandhi project.pdf graphic design
BIT Khushi gandhi project.pdf graphic design
 
FW25-26 Fashion Key Items Trend Book Peclers Paris
FW25-26 Fashion Key Items Trend Book Peclers ParisFW25-26 Fashion Key Items Trend Book Peclers Paris
FW25-26 Fashion Key Items Trend Book Peclers Paris
 
一比一原版格林威治大学毕业证成绩单如何办理
一比一原版格林威治大学毕业证成绩单如何办理一比一原版格林威治大学毕业证成绩单如何办理
一比一原版格林威治大学毕业证成绩单如何办理
 
Claire's designing portfolio presentation
Claire's designing portfolio presentationClaire's designing portfolio presentation
Claire's designing portfolio presentation
 
一比一原版谢菲尔德大学毕业证成绩单如何办理
一比一原版谢菲尔德大学毕业证成绩单如何办理一比一原版谢菲尔德大学毕业证成绩单如何办理
一比一原版谢菲尔德大学毕业证成绩单如何办理
 
Design lessons from Singapore | Volume 3
Design lessons from Singapore | Volume 3Design lessons from Singapore | Volume 3
Design lessons from Singapore | Volume 3
 
Week of Action 2022_EIT Climate-KIC_Headers
Week of Action 2022_EIT Climate-KIC_HeadersWeek of Action 2022_EIT Climate-KIC_Headers
Week of Action 2022_EIT Climate-KIC_Headers
 
Knowing, Understanding and Planning Cities- Role and Relevance Physical Plan...
Knowing, Understanding and Planning Cities- Role and Relevance  Physical Plan...Knowing, Understanding and Planning Cities- Role and Relevance  Physical Plan...
Knowing, Understanding and Planning Cities- Role and Relevance Physical Plan...
 
NO1 Popular kala jadu karne wale ka contact number kala jadu karne wale baba ...
NO1 Popular kala jadu karne wale ka contact number kala jadu karne wale baba ...NO1 Popular kala jadu karne wale ka contact number kala jadu karne wale baba ...
NO1 Popular kala jadu karne wale ka contact number kala jadu karne wale baba ...
 
Dos And Dont's Of Logo Design For 2024..
Dos And Dont's Of Logo Design For 2024..Dos And Dont's Of Logo Design For 2024..
Dos And Dont's Of Logo Design For 2024..
 
Heidi Livengood's Professional CADD Portfolio
Heidi Livengood's Professional CADD PortfolioHeidi Livengood's Professional CADD Portfolio
Heidi Livengood's Professional CADD Portfolio
 
Spring 2024 wkrm_Enhancing Campus Mobility.pdf
Spring 2024 wkrm_Enhancing Campus Mobility.pdfSpring 2024 wkrm_Enhancing Campus Mobility.pdf
Spring 2024 wkrm_Enhancing Campus Mobility.pdf
 
Eric Parein CV. Parein in English is best pronounced as PARE-IN
Eric Parein CV. Parein in English is best pronounced as PARE-INEric Parein CV. Parein in English is best pronounced as PARE-IN
Eric Parein CV. Parein in English is best pronounced as PARE-IN
 
Redefining Globalization, urbanisation and Localisation
Redefining Globalization, urbanisation and LocalisationRedefining Globalization, urbanisation and Localisation
Redefining Globalization, urbanisation and Localisation
 
Recycled Modular Low Cost Construction .pdf
Recycled Modular Low Cost Construction .pdfRecycled Modular Low Cost Construction .pdf
Recycled Modular Low Cost Construction .pdf
 
Heuristic Evaluation of System & Application
Heuristic Evaluation of System & ApplicationHeuristic Evaluation of System & Application
Heuristic Evaluation of System & Application
 
iF_Design_Trend_Report_twentytwenrythree
iF_Design_Trend_Report_twentytwenrythreeiF_Design_Trend_Report_twentytwenrythree
iF_Design_Trend_Report_twentytwenrythree
 
Abdulaziz Tariq Abdulaziz Mustafa CV 2024
Abdulaziz Tariq Abdulaziz Mustafa CV 2024Abdulaziz Tariq Abdulaziz Mustafa CV 2024
Abdulaziz Tariq Abdulaziz Mustafa CV 2024
 

Proxy Design Pattern

  • 1. Proxy Design Pattern Anjan Kumar BollamSrikanth Gorlla Design Patterns Summer 09
  • 2. Example – Financial proxy 6/15/09 2
  • 3. Questions on Proxy design pattern What is the intent of Proxy Design Pattern? What is the motivation of Proxy Design Pattern? If a Proxy is used to instantiate an object only when it is absolutely needed, does the Proxy simplify code? How to handle multiple copies of the Complex Object using Proxy? What are the advantages of using Proxy? What are the other related patterns for Proxy? When do we use Proxy Design Pattern? 6/15/09 3
  • 4.
  • 5.
  • 6.
  • 7. Proxy also allows us to vary how and where an object is accessed.
  • 8.
  • 9. When you need to represent an object that is complex or time consuming to create with a simpler one.6/15/09 5
  • 10.
  • 11. Loading of Graphical images takes time.
  • 12. This may slow down the opening of the document.
  • 13. But what to put instead of the actual object while initializing?We can use a PROXY 6/15/09 6
  • 14.
  • 15. Takes care of instantiating the real object when required by invoking the draw() function.
  • 16. Forwards the subsequent requests directly to the image
  • 17. Creates the real image only when the document editor asks it to 6/15/09 7
  • 18.
  • 19. Applicable Situations A remote proxy provides a local representative for an object in a different address space A virtual proxy creates expensive objects on demand. A protection proxy controls access to the original object. A smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed. 6/15/09 9
  • 20.
  • 21. loading a persistent object into memory when it's first referenced.
  • 22. checking that the real object is locked before it's accessed to ensure that no other object can change it.6/15/09 10
  • 23. Structure – Class Diagram 6/15/09 11 Provide a surrogate or placeholder for another object to control access to it.
  • 24. Structure – Object Diagram 6/15/09 12
  • 25.
  • 27.
  • 28. Provides an interface identical to subject's so that a proxy can by substituted for the real subject.
  • 29.
  • 30. Collaborations 6/15/09 18 Proxy forwards requests to Real Subject when appropriate, depending on the kind of proxy.
  • 31.
  • 32. A virtual proxy can perform optimizations such as creating an object on demand.
  • 33. Both protection proxies and smart references allow additional housekeeping tasks when an object is accessed. 6/15/09 19
  • 34.
  • 35.
  • 36.
  • 37. Overloading the member access pointer class Image; // external function extern Image* LoadAnImageFile(const char*); class ImagePtr { public: ImagePtr(const char* imageFile); virtual ~ImagePtr(); virtual Image* operator->(); virtual Image& operator*(); private: Image* LoadImage(); private: Image* _image; const char* _imageFile; }; 6/15/09 22
  • 38.
  • 39. Overloading the member access pointer The overloaded -> and * methods call the LoadImage() to return the _image object. Image* ImagePtr::operator-> () { return LoadImage(); } Image& ImagePtr::operator* () { return *LoadImage(); } 6/15/09 24
  • 40. Overloading the member access pointer This approach allows us to call Image class operations through ImagePtr objects without going to the trouble of making the Image class operations part of the ImagePtr interface: ImagePtr image = ImagePtr("anImageFileName"); image->Draw(Point(50, 100)); //(image.operator->())->Draw(Point(50,100)) This isn’t a good solution to every kind of proxy, where the proxy need to know precisely which operation is called. For example, in the virtual proxy example presented in Motivation, image should be referenced when the Draw operation is called. 6/15/09 25
  • 41.
  • 42.
  • 43.
  • 44. Known Uses NEXTSTEP [Add94] uses proxies (instances of class NXProxy) as local representatives for objects that may be distributed. World Wide Web Proxy generally runs on a firewall machine and allows people inside the firewall concurrent access to the outside world. In Microsoft’s OLE DB, proxies hide whether a specific server is local or remote from a client. 6/15/09 29
  • 45. Related patterns Adapter Adapter Pattern provides a different interface to its subject. Proxy provides the same interface. Decorator Proxy provides the same interface. Decorator Pattern provides an enhanced interface 6/15/09 30
  • 46. References Design Patterns, Elements of Reusable Object-Oriented Software, Erich Gamma, et. al., Addison-Wesley, 1994 Head First Design Patterns by Eric Freeman & Elisabeth Freeman http://www.dofactory.com/Patterns/PatternProxy.aspx http://home.earthlink.net/~huston2/dp/proxy.html http://en.wikipedia.org/wiki/Proxy_pattern http://dotnetperls.com/protection-proxy 6/15/09 31
  • 47. Questions on Proxy design pattern What is the intent of Proxy Design Pattern? What is the motivation of Proxy Design Pattern? If a Proxy is used to instantiate an object only when it is absolutely needed, does the Proxy simplify code? How to handle multiple copies of the Complex Object using Proxy? What are the advantages of using Proxy? What are the other related patterns for Proxy? When do we use Proxy Design Pattern? 6/15/09 32