SlideShare a Scribd company logo
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

Creational pattern
Creational patternCreational pattern
Creational patternHimanshu
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Patternsahilrk911
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern PresentationJAINIK PATEL
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design PatternShahriar Hyder
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design PatternVarun Arora
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)paramisoft
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternMudasir Qazi
 
The State Design Pattern
The State Design PatternThe State Design Pattern
The State Design PatternJosh Candish
 

What's hot (20)

Composite pattern
Composite patternComposite pattern
Composite pattern
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Java rmi
Java rmiJava rmi
Java rmi
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Java RMI
Java RMIJava RMI
Java RMI
 
The State Design Pattern
The State Design PatternThe State Design Pattern
The State Design Pattern
 

Viewers also liked

Software design patterns ppt
Software design patterns pptSoftware design patterns ppt
Software design patterns pptmkruthika
 
The Decorator Pattern
The Decorator PatternThe Decorator Pattern
The Decorator PatternAkshat Vig
 
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 Patterneprafulla
 
Template method pattern example
Template method pattern exampleTemplate method pattern example
Template method pattern exampleGuo Albert
 
Bridge pattern for Dummies
Bridge pattern for DummiesBridge pattern for Dummies
Bridge pattern for DummiesTaekSoon Jang
 
Design Pattern - Singleton Pattern
Design Pattern - Singleton PatternDesign Pattern - Singleton Pattern
Design Pattern - Singleton PatternMudasir Qazi
 
Soa Overview
Soa OverviewSoa Overview
Soa OverviewTerry Cho
 
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 patternJoao Pereira
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
 
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,...Svetlin Nakov
 
Software Engineering ppt
Software Engineering pptSoftware Engineering ppt
Software Engineering pptshruths2890
 
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 PatternNishith Shukla
 

Viewers also liked (17)

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
 
Design Pattern - Singleton Pattern
Design Pattern - Singleton PatternDesign Pattern - Singleton Pattern
Design Pattern - Singleton Pattern
 
Soa Overview
Soa OverviewSoa Overview
Soa Overview
 
Design pattern
Design patternDesign pattern
Design pattern
 
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
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
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 PatternMainak Goswami
 
Design Patterns - Part 2 of 2
Design Patterns - Part 2 of 2Design Patterns - Part 2 of 2
Design Patterns - Part 2 of 2Savio Sebastian
 
Introduction-to-Design-Patternsssss.pptx
Introduction-to-Design-Patternsssss.pptxIntroduction-to-Design-Patternsssss.pptx
Introduction-to-Design-Patternsssss.pptxLightOFC1
 
Chrome & Webkit overview
Chrome & Webkit overviewChrome & Webkit overview
Chrome & Webkit overviewBin Chen
 
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 conceptsRahul Malhotra
 
Design patterns through java
Design patterns through javaDesign patterns through java
Design patterns through javaAditya Bhuyan
 
Opendelight reference-guide
Opendelight reference-guideOpendelight reference-guide
Opendelight reference-guideAshwini Rath
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningSyed Irtaza Ali
 
Machine Learning Use Case - Agriculture
Machine Learning Use Case - AgricultureMachine Learning Use Case - Agriculture
Machine Learning Use Case - AgricultureNilabja GhoshChowdhury
 
SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11SCWCD : Web tier design CHAP : 11
SCWCD : Web tier design CHAP : 11Ben Abdallah Helmi
 
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 Seminarcontest-theta360
 
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 BootVMware Tanzu
 
Understanding AngularJS HTML5 DataServices
Understanding AngularJS HTML5 DataServicesUnderstanding AngularJS HTML5 DataServices
Understanding AngularJS HTML5 DataServicesThomas Burleson
 
Android architecture
Android architecture Android architecture
Android architecture Trong-An Bui
 
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.docxjuliennehar
 
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
 
1 croreprojects dotnet ppt
1 croreprojects dotnet ppt1 croreprojects dotnet ppt
1 croreprojects dotnet pptKumar Dlk
 

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
 
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...
 
1 croreprojects dotnet ppt
1 croreprojects dotnet ppt1 croreprojects dotnet ppt
1 croreprojects dotnet ppt
 

Recently uploaded

Design lessons from Singapore | Volume 3
Design lessons from Singapore | Volume 3Design lessons from Singapore | Volume 3
Design lessons from Singapore | Volume 3Remy Rey De Barros
 
Art Nouveau Movement Presentation for Art History.
Art Nouveau Movement Presentation for Art History.Art Nouveau Movement Presentation for Art History.
Art Nouveau Movement Presentation for Art History.rrimika1
 
CA OFFICE office office office _VIEWS.pdf
CA OFFICE office office office _VIEWS.pdfCA OFFICE office office office _VIEWS.pdf
CA OFFICE office office office _VIEWS.pdfSudhanshuMandlik
 
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.pdfJon Freach
 
Common Designing Mistakes and How to avoid them
Common Designing Mistakes and How to avoid themCommon Designing Mistakes and How to avoid them
Common Designing Mistakes and How to avoid themmadhavlakhanpal29
 
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdfPORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdffabianavillanib
 
National-Learning-Camp 2024 deped....pptx
National-Learning-Camp 2024 deped....pptxNational-Learning-Camp 2024 deped....pptx
National-Learning-Camp 2024 deped....pptxAlecAnidul
 
Pitch Presentation for Service Design in Technology
Pitch Presentation for Service Design in TechnologyPitch Presentation for Service Design in Technology
Pitch Presentation for Service Design in TechnologyJaime Brown
 
Claire's designing portfolio presentation
Claire's designing portfolio presentationClaire's designing portfolio presentation
Claire's designing portfolio presentationssuser8fae18
 
Heuristic Evaluation of System & Application
Heuristic Evaluation of System & ApplicationHeuristic Evaluation of System & Application
Heuristic Evaluation of System & ApplicationJaime Brown
 
The Design Code Google Developer Student Club.pptx
The Design Code Google Developer Student Club.pptxThe Design Code Google Developer Student Club.pptx
The Design Code Google Developer Student Club.pptxadityakushalsaha
 
The Evolution of Fashion Trends: History to Fashion
The Evolution of Fashion Trends: History to FashionThe Evolution of Fashion Trends: History to Fashion
The Evolution of Fashion Trends: History to FashionPixel poets
 
Research about Venice ppt for grade 6f anas
Research about Venice ppt for grade 6f anasResearch about Venice ppt for grade 6f anas
Research about Venice ppt for grade 6f anasanasabutalha2013
 
BIT- Pinal .H. Prajapati Graphic Designer
BIT- Pinal .H. Prajapati  Graphic DesignerBIT- Pinal .H. Prajapati  Graphic Designer
BIT- Pinal .H. Prajapati Graphic Designerbitwgin12
 

Recently uploaded (14)

Design lessons from Singapore | Volume 3
Design lessons from Singapore | Volume 3Design lessons from Singapore | Volume 3
Design lessons from Singapore | Volume 3
 
Art Nouveau Movement Presentation for Art History.
Art Nouveau Movement Presentation for Art History.Art Nouveau Movement Presentation for Art History.
Art Nouveau Movement Presentation for Art History.
 
CA OFFICE office office office _VIEWS.pdf
CA OFFICE office office office _VIEWS.pdfCA OFFICE office office office _VIEWS.pdf
CA OFFICE office office office _VIEWS.pdf
 
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
 
Common Designing Mistakes and How to avoid them
Common Designing Mistakes and How to avoid themCommon Designing Mistakes and How to avoid them
Common Designing Mistakes and How to avoid them
 
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdfPORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
PORTFOLIO FABIANA VILLANI ARCHITECTURE.pdf
 
National-Learning-Camp 2024 deped....pptx
National-Learning-Camp 2024 deped....pptxNational-Learning-Camp 2024 deped....pptx
National-Learning-Camp 2024 deped....pptx
 
Pitch Presentation for Service Design in Technology
Pitch Presentation for Service Design in TechnologyPitch Presentation for Service Design in Technology
Pitch Presentation for Service Design in Technology
 
Claire's designing portfolio presentation
Claire's designing portfolio presentationClaire's designing portfolio presentation
Claire's designing portfolio presentation
 
Heuristic Evaluation of System & Application
Heuristic Evaluation of System & ApplicationHeuristic Evaluation of System & Application
Heuristic Evaluation of System & Application
 
The Design Code Google Developer Student Club.pptx
The Design Code Google Developer Student Club.pptxThe Design Code Google Developer Student Club.pptx
The Design Code Google Developer Student Club.pptx
 
The Evolution of Fashion Trends: History to Fashion
The Evolution of Fashion Trends: History to FashionThe Evolution of Fashion Trends: History to Fashion
The Evolution of Fashion Trends: History to Fashion
 
Research about Venice ppt for grade 6f anas
Research about Venice ppt for grade 6f anasResearch about Venice ppt for grade 6f anas
Research about Venice ppt for grade 6f anas
 
BIT- Pinal .H. Prajapati Graphic Designer
BIT- Pinal .H. Prajapati  Graphic DesignerBIT- Pinal .H. Prajapati  Graphic Designer
BIT- Pinal .H. Prajapati Graphic Designer
 

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