SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

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
 
Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design PatternsLidan Hifi
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design PatternVarun Arora
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternMudasir Qazi
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design PatternAdeel Riaz
 
Design Pattern - Chain of Responsibility
Design Pattern - Chain of ResponsibilityDesign Pattern - Chain of Responsibility
Design Pattern - Chain of ResponsibilityMudasir Qazi
 
Visitor Pattern
Visitor PatternVisitor Pattern
Visitor PatternIder Zheng
 
Chain of responsibility pattern
Chain of responsibility patternChain of responsibility pattern
Chain of responsibility patternKuntanSutar
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns pptAman Jain
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Patternguy_davis
 
Prototype design patterns
Prototype design patternsPrototype design patterns
Prototype design patternsThaichor Seng
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility PatternHüseyin Ergin
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern Nirthika Rajendran
 

Mais procurados (20)

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
 
Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design Patterns
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Design Pattern - Chain of Responsibility
Design Pattern - Chain of ResponsibilityDesign Pattern - Chain of Responsibility
Design Pattern - Chain of Responsibility
 
Visitor Pattern
Visitor PatternVisitor Pattern
Visitor Pattern
 
Chain of responsibility pattern
Chain of responsibility patternChain of responsibility pattern
Chain of responsibility pattern
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
JNDI
JNDIJNDI
JNDI
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Prototype design patterns
Prototype design patternsPrototype design patterns
Prototype design patterns
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern
 

Semelhante a 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
 

Semelhante a 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
 

Mais 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
 

Mais de 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
 
Flyweight Pattern
Flyweight PatternFlyweight Pattern
Flyweight Pattern
 

Último

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Último (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

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