SlideShare une entreprise Scribd logo
1  sur  20
Pattern

Structural Pattern
Warm-up
       You want to impress your girlfriend by
        carrying a 250 lbs box (what an impression).
       It is not easy as you see!

       What to do?                         He he


       Create another box of exactly
        the same look, but lighter.
       Now you can go!
       The ‘not that heavy’ box
        is the proxy of the normal box.
       But still makes the same effect 

    2
Another Example –                     This time Serious

       Drawback money from the
        bank!
       We will not go to a bank
        branch.
       Just go to an ATM.
       Get the cash!
       So ATM is some kind of a
        bank.
           With reduced functionalities.
       ATM is also a proxy to the
        bank!
    3
Proxy Pattern
       Proxy pattern comes into play when we have
        HeavyWeight objects and
           We want to implement a simpler version of a
            HeavyWeight object.
           We don’t need the whole functionality of the HeavyWeight
            object.
           We want to limit the access to the HeavyWeight object.
       Because there may be a time-delay or complex
        mechanism in creating instances of HeavyWeight
        objects.
       Proxy pattern is also known as «surrogate».
           Means to put something into place of another
    4
Proxy Pattern Structure




5
Concrete Structure




6
Participants
       Subject (Bank)
           The common interface for the proxy and the real subject
       Real Subject (Bank Branch)
           The concrete subject that implements the interface.
       Proxy (ATM)
           Provides the same interface as Real Subject (or a subset)
           Maintains a reference to the Real Subject
           Since it doesnot have all the data as Real Subject (a
            lightweight), it can do many things faster than Real
            Subject.
           Then invokes Real Subject (if needed).

    7
Object & Sequence Diagrams




8
Consequences
       A level of indirection while accessing real subject.
           We can think this as another tier between real subject and
            us.
       We want to support heavyweight objects, but we
        want to create only when they are requested.
           Memory will not get full.
           Programs will run faster.
       It is like giving a small example of the same subject.
           Most of the times, proxy will have same interfaces as
            subject.
           Programmers can declare variables without caring
            whether a proxy or the heavyweight will be put.
    9
Disadvantages
    Do you think of any disadvantages?
    Identity Comparison
        We can’t do identity comparison since we don’t know
         exact real subject, just a surrogate.
    Inambiguity
        Client may not be aware that the real subject it is
         accessing now is not same as the previous one.
        Because client doesn’t know what else proxy is doing,
         other than calling real subject.




    10
Variants
    Remote Proxy:
        Provides a local represent of an object in different
         address space (or maybe in same address)




    11
Variants – cont’d
    Virtual Proxy:
        When we have so many heavyweight objects, we can
         create virtual proxies for objects to load program faster.
        Program can start with proxies and real subjects may be
         downloaded on background (or when requested).




    12
Variants – cont’d
    Access Control Proxy:
        Act as an controller between the real subject and clients.
        Example: Normal proxy server in modern web




    13
Variants – cont’d
    Smart Reference Proxy:
        Provides additional actions whenever a real subject is
         referenced.
            Counting the number of accesses
            Locking it so that only one object can change at a time.
            Deleting an object after a certain number of accesses.
    Cache Proxy:
        Provides temporary storage of results of the expensive
         target operations.
        Make some certain operations faster!



    14
Relation with Other Patterns
    Adapter Pattern
        Implements a difference interface to the object it adapts
    Proxy Pattern
        Implements same interface as its subject




    15
Relation with Other Patterns – cont’d
    Decorator Pattern vs Proxy Pattern
        Both patterns describe a level of indirection to an object
        Implementations of both keeps a reference to another
         object
        But they are intended for different purposes
            Decorator is adding more responsibilities to the object while
             decorating
            Proxy is controlling access to it




    16
Demo Time
    An image displayer
    First shows the proxy with a default image.
    When load pressed, it will load the actual image.
     (Bigger and HD)

    UML diagram is on the right.
    See the proxy pattern?

    Demo from
     Design Patterns in Java 2nd Edition
     Steven John Metsker, William C. Wake



    17
Thanks




         Questions?

18
References
    GoF Design Patterns Book
    The ‘not that strong’ man: http://www.revolutionhealth.com/articles/proper-lifting-
     technique/hw206944
    The impressed girl: http://www.shutterstock.com/pic-10016596/stock-photo-surprised-
     girl-pointing-at-copy-space-portrait-of-a-beautiful-young-business-woman-looking-
     up.html
    The bank: http://chinarsuvidhaacenter.org/
    The ATM Machine: http://www.clipartheaven.com/show/clipart/money/atm-gif.html
    Variant images: O’Reilly Head First Design Patterns book
    Access Control Proxy image: http://www.democracybroadcastingnews.com/?p=12329
    http://www.site.uottawa.ca:4321/oose/index.html#proxy
    Anti-pattern from: The patterns handbook: techniques, strategies, and
     applications By Linda Rising (google books has this book)
    http://blog.decayingcode.com/post/anti-pattern-god-object.aspx
    http://www.oodesign.com/proxy-pattern.html
    http://www.javacamp.org/designPattern/proxy.html
    Demo from book: http://www.informit.com/store/product.aspx?isbn=0321333020
    19
Bonus: Introducing Anti-Patterns
    Anti-patterns are a way of making the things wrong.
    Remember Edison?
        Tried hundreds of possible materials for flament till
         building the first electric light.
        At each failure, he knows what he shouldn’t do next time!
    Designs may end up with an anti-pattern by:
        Developer or designer’s not knowing better
        Not having sufficient experience for specific problems
        Or applying a perfectly good pattern in the wrong context.
    One example is «God Object»
        An object that knows too much or does too much
        Result of a mis-use of facade pattern

    20

Contenu connexe

Tendances

Command Design Pattern
Command Design Pattern Command Design Pattern
Command Design Pattern anil kanzariya
 
Observer design pattern
Observer design patternObserver design pattern
Observer design patternSara Torkey
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibilityShakil Ahmed
 
Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Sameer Rathoud
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design PatternShahriar Hyder
 
Design Pattern - Observer Pattern
Design Pattern - Observer PatternDesign Pattern - Observer Pattern
Design Pattern - Observer PatternMudasir Qazi
 
Android resources
Android resourcesAndroid resources
Android resourcesma-polimi
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3Ilio Catallo
 
Android resource
Android resourceAndroid resource
Android resourceKrazy Koder
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVAJalpesh Vasa
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in JavaInnovationM
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMIbackdoor
 

Tendances (20)

Command Design Pattern
Command Design Pattern Command Design Pattern
Command Design Pattern
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Sql injection
Sql injectionSql injection
Sql injection
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
 
Mediator Design Pattern
Mediator Design PatternMediator Design Pattern
Mediator Design Pattern
 
Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)Proxy design pattern (Class Ambassador)
Proxy design pattern (Class Ambassador)
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
 
Design Pattern - Observer Pattern
Design Pattern - Observer PatternDesign Pattern - Observer Pattern
Design Pattern - Observer Pattern
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Android resources
Android resourcesAndroid resources
Android resources
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3
 
Android resource
Android resourceAndroid resource
Android resource
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in Java
 
Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
 

Similaire à Proxy Pattern

Design patterns through java
Design patterns through javaDesign patterns through java
Design patterns through javaAditya Bhuyan
 
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
 
Javascript spaghetti stirtrek_5_17
Javascript  spaghetti stirtrek_5_17Javascript  spaghetti stirtrek_5_17
Javascript spaghetti stirtrek_5_17Jared Faris
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiJared Faris
 
Dependency Injection Lightning Talk
Dependency Injection Lightning TalkDependency Injection Lightning Talk
Dependency Injection Lightning TalkJon Bachelor
 
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
 
Designing Powerful Web Applications - Monterey
Designing Powerful Web Applications - MontereyDesigning Powerful Web Applications - Monterey
Designing Powerful Web Applications - MontereyDave Malouf
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)alloy020
 
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
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsLalit Kale
 
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
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core ConceptsDivyang Bhambhani
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Bill Buchan
 
Test slideshow
Test slideshowTest slideshow
Test slideshowlegacye
 
Test slideshow
Test slideshowTest slideshow
Test slideshowlegacye
 
Test slideshow
Test slideshowTest slideshow
Test slideshowlegacye
 

Similaire à Proxy Pattern (20)

Design patterns through java
Design patterns through javaDesign patterns through java
Design patterns through java
 
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
 
Javascript spaghetti stirtrek_5_17
Javascript  spaghetti stirtrek_5_17Javascript  spaghetti stirtrek_5_17
Javascript spaghetti stirtrek_5_17
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript Spaghetti
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Dependency Injection Lightning Talk
Dependency Injection Lightning TalkDependency Injection Lightning Talk
Dependency Injection Lightning Talk
 
Gang of four Proxy Design Pattern
 Gang of four Proxy Design Pattern Gang of four Proxy Design Pattern
Gang of four Proxy Design Pattern
 
Designing Powerful Web Applications - Monterey
Designing Powerful Web Applications - MontereyDesigning Powerful Web Applications - Monterey
Designing Powerful Web Applications - Monterey
 
DCI with Ruby and Rails
DCI with Ruby and RailsDCI with Ruby and Rails
DCI with Ruby and Rails
 
Monk objects
Monk objectsMonk objects
Monk objects
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)
 
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
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
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
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core Concepts
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
 
Test slideshow
Test slideshowTest slideshow
Test slideshow
 
Test slideshow
Test slideshowTest slideshow
Test slideshow
 
Test slideshow
Test slideshowTest slideshow
Test slideshow
 

Plus de Hüseyin Ergin

Is there life after code?
Is there life after code?Is there life after code?
Is there life after code?Hüseyin Ergin
 
SITE - CS Presentation
SITE - CS PresentationSITE - CS Presentation
SITE - CS PresentationHüseyin Ergin
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingHüseyin Ergin
 
Software Versioning with Bitbucket and Eclipse
Software Versioning with Bitbucket and EclipseSoftware Versioning with Bitbucket and Eclipse
Software Versioning with Bitbucket and EclipseHüseyin Ergin
 
From the book: 50 Proven Ways to Be Persuasive
From the book: 50 Proven Ways to Be PersuasiveFrom the book: 50 Proven Ways to Be Persuasive
From the book: 50 Proven Ways to Be PersuasiveHüseyin Ergin
 
Object Oriented Paradigm
Object Oriented ParadigmObject Oriented Paradigm
Object Oriented ParadigmHüseyin Ergin
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility PatternHüseyin Ergin
 

Plus de Hüseyin Ergin (8)

Is there life after code?
Is there life after code?Is there life after code?
Is there life after code?
 
SITE - CS Presentation
SITE - CS PresentationSITE - CS Presentation
SITE - CS Presentation
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Software Versioning with Bitbucket and Eclipse
Software Versioning with Bitbucket and EclipseSoftware Versioning with Bitbucket and Eclipse
Software Versioning with Bitbucket and Eclipse
 
From the book: 50 Proven Ways to Be Persuasive
From the book: 50 Proven Ways to Be PersuasiveFrom the book: 50 Proven Ways to Be Persuasive
From the book: 50 Proven Ways to Be Persuasive
 
Object Oriented Paradigm
Object Oriented ParadigmObject Oriented Paradigm
Object Oriented Paradigm
 
Flyweight Pattern
Flyweight PatternFlyweight Pattern
Flyweight Pattern
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
 

Dernier

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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 WorkerThousandEyes
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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.pdfsudhanshuwaghmare1
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 

Dernier (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

Proxy Pattern

  • 2. Warm-up  You want to impress your girlfriend by carrying a 250 lbs box (what an impression).  It is not easy as you see!  What to do? He he  Create another box of exactly the same look, but lighter.  Now you can go!  The ‘not that heavy’ box is the proxy of the normal box.  But still makes the same effect  2
  • 3. Another Example – This time Serious  Drawback money from the bank!  We will not go to a bank branch.  Just go to an ATM.  Get the cash!  So ATM is some kind of a bank.  With reduced functionalities.  ATM is also a proxy to the bank! 3
  • 4. Proxy Pattern  Proxy pattern comes into play when we have HeavyWeight objects and  We want to implement a simpler version of a HeavyWeight object.  We don’t need the whole functionality of the HeavyWeight object.  We want to limit the access to the HeavyWeight object.  Because there may be a time-delay or complex mechanism in creating instances of HeavyWeight objects.  Proxy pattern is also known as «surrogate».  Means to put something into place of another 4
  • 7. Participants  Subject (Bank)  The common interface for the proxy and the real subject  Real Subject (Bank Branch)  The concrete subject that implements the interface.  Proxy (ATM)  Provides the same interface as Real Subject (or a subset)  Maintains a reference to the Real Subject  Since it doesnot have all the data as Real Subject (a lightweight), it can do many things faster than Real Subject.  Then invokes Real Subject (if needed). 7
  • 8. Object & Sequence Diagrams 8
  • 9. Consequences  A level of indirection while accessing real subject.  We can think this as another tier between real subject and us.  We want to support heavyweight objects, but we want to create only when they are requested.  Memory will not get full.  Programs will run faster.  It is like giving a small example of the same subject.  Most of the times, proxy will have same interfaces as subject.  Programmers can declare variables without caring whether a proxy or the heavyweight will be put. 9
  • 10. Disadvantages  Do you think of any disadvantages?  Identity Comparison  We can’t do identity comparison since we don’t know exact real subject, just a surrogate.  Inambiguity  Client may not be aware that the real subject it is accessing now is not same as the previous one.  Because client doesn’t know what else proxy is doing, other than calling real subject. 10
  • 11. Variants  Remote Proxy:  Provides a local represent of an object in different address space (or maybe in same address) 11
  • 12. Variants – cont’d  Virtual Proxy:  When we have so many heavyweight objects, we can create virtual proxies for objects to load program faster.  Program can start with proxies and real subjects may be downloaded on background (or when requested). 12
  • 13. Variants – cont’d  Access Control Proxy:  Act as an controller between the real subject and clients.  Example: Normal proxy server in modern web 13
  • 14. Variants – cont’d  Smart Reference Proxy:  Provides additional actions whenever a real subject is referenced.  Counting the number of accesses  Locking it so that only one object can change at a time.  Deleting an object after a certain number of accesses.  Cache Proxy:  Provides temporary storage of results of the expensive target operations.  Make some certain operations faster! 14
  • 15. Relation with Other Patterns  Adapter Pattern  Implements a difference interface to the object it adapts  Proxy Pattern  Implements same interface as its subject 15
  • 16. Relation with Other Patterns – cont’d  Decorator Pattern vs Proxy Pattern  Both patterns describe a level of indirection to an object  Implementations of both keeps a reference to another object  But they are intended for different purposes  Decorator is adding more responsibilities to the object while decorating  Proxy is controlling access to it 16
  • 17. Demo Time  An image displayer  First shows the proxy with a default image.  When load pressed, it will load the actual image. (Bigger and HD)  UML diagram is on the right.  See the proxy pattern?  Demo from Design Patterns in Java 2nd Edition Steven John Metsker, William C. Wake 17
  • 18. Thanks Questions? 18
  • 19. References  GoF Design Patterns Book  The ‘not that strong’ man: http://www.revolutionhealth.com/articles/proper-lifting- technique/hw206944  The impressed girl: http://www.shutterstock.com/pic-10016596/stock-photo-surprised- girl-pointing-at-copy-space-portrait-of-a-beautiful-young-business-woman-looking- up.html  The bank: http://chinarsuvidhaacenter.org/  The ATM Machine: http://www.clipartheaven.com/show/clipart/money/atm-gif.html  Variant images: O’Reilly Head First Design Patterns book  Access Control Proxy image: http://www.democracybroadcastingnews.com/?p=12329  http://www.site.uottawa.ca:4321/oose/index.html#proxy  Anti-pattern from: The patterns handbook: techniques, strategies, and applications By Linda Rising (google books has this book)  http://blog.decayingcode.com/post/anti-pattern-god-object.aspx  http://www.oodesign.com/proxy-pattern.html  http://www.javacamp.org/designPattern/proxy.html  Demo from book: http://www.informit.com/store/product.aspx?isbn=0321333020 19
  • 20. Bonus: Introducing Anti-Patterns  Anti-patterns are a way of making the things wrong.  Remember Edison?  Tried hundreds of possible materials for flament till building the first electric light.  At each failure, he knows what he shouldn’t do next time!  Designs may end up with an anti-pattern by:  Developer or designer’s not knowing better  Not having sufficient experience for specific problems  Or applying a perfectly good pattern in the wrong context.  One example is «God Object»  An object that knows too much or does too much  Result of a mis-use of facade pattern 20