SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Command Pattern
Command PatternCommand Pattern
Command Pattern
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design Pattern
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Memento pattern
Memento patternMemento pattern
Memento pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Java concurrency in practice
Java concurrency in practiceJava concurrency in practice
Java concurrency in practice
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Bridge pattern for Dummies
Bridge pattern for DummiesBridge pattern for Dummies
Bridge pattern for Dummies
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Flyweight Pattern
Flyweight PatternFlyweight Pattern
Flyweight Pattern
 
State
StateState
State
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Prototype_pattern
Prototype_patternPrototype_pattern
Prototype_pattern
 
Composite design pattern
Composite design patternComposite design pattern
Composite design pattern
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von Hüseyin Ergin (7)

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
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
 

Kürzlich hochgeladen

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Kürzlich hochgeladen (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

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