Design Patterns - 02 Proxy and Bridge Pattern


Published on

This is my second presentation about design patterns. It covers proxy and bridge patterns.

Published in: Design
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Decouple means to have things behave independently from each other or at least explicitly state what the relationship is.Abstraction is how different things are related to each other conecptually.
  • Design Patterns - 02 Proxy and Bridge Pattern

    1. 1. 02 Proxy and Bridge Pattern<br />Design Patterns<br />© Prafulla Paraskar 2010<br />
    2. 2. Proxy<br />Structural Design Pattern<br />
    3. 3. Definition<br />A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. (wikipedia)<br />© Prafulla Paraskar 2010<br />
    4. 4. Proxy Pattern – Explained (1/2)<br />Resources<br />Proxy<br />Client<br />© Prafulla Paraskar 2010<br />
    5. 5. Proxy Pattern – Explained (2/2)<br />Provides a surrogate or placeholder for another object to control access to it.<br />A mechanism to enforce authentication and authorization. <br />Creates expensive objects only when required.<br />Allows optimization techniques such as caching to be implemented.<br />Release expensive resources soon as they are no longer required (smart pointers).<br />© Prafulla Paraskar 2010<br />
    6. 6. Proxy Pattern – UML Diagram<br />© Prafulla Paraskar 2010<br />
    7. 7. Proxy Pattern – Real World Samples<br />Image/document editors.<br />Reference counting pointer (smart pointer).<br />Friend lists on social networking sites.<br />COM Components at the lower level.<br />CORBA proxy/stub objects.<br />.NET web services proxy classes.<br />© Prafulla Paraskar 2010<br />
    8. 8. Proxy Pattern – Guidelines (1/2)<br />You have objects that:<br />Are expensive to create.<br />Need access control.<br />Access remote sites.<br />Need to perform some action whenever they are accessed.<br />© Prafulla Paraskar 2010<br />
    9. 9. Proxy Pattern – Guidelines (2/2)<br />You want to:<br />Create objects only when their operations are requested.<br />Perform checks or housekeeping on objects whenever accessed.<br />Have a local object that will refer to a remote object.<br />Implement access rights on objects as their operations are requested.<br />© Prafulla Paraskar 2010<br />
    10. 10. Bridge<br />Structural Design Pattern<br />
    11. 11. Definition<br />The bridge pattern is a design pattern used in software engineering which is meant to "decouple an abstraction from its implementation so that the two can vary independently“.(wikipedia)<br />© Prafulla Paraskar 2010<br />
    12. 12. Bridge Pattern – Explained (1/2)<br />© Prafulla Paraskar 2010<br />
    13. 13. Bridge Pattern – Explained (2/2)<br />Decouples an abstraction from implementation.<br />Specially useful in the situations where a new version of component library needs to replace older one with backward compatibility.<br />Client specifies which implementation to use (sometimes implicitly).<br />Unlike Adapter pattern, client knows about the implementation in use all the time.<br />© Prafulla Paraskar 2010<br />
    14. 14. Bridge Pattern – UML Diagram<br />© Prafulla Paraskar 2010<br />
    15. 15. BridgePattern – Real World Samples<br />Electric switch (abstraction) / Appliances (implementations). <br />Different types of displays (implementation) providing one essential set of capabilities defined in the a bridge interface (abstraction). Client calls the abstraction to display something and the abstraction deciding the display based on the capabilities.<br />© Prafulla Paraskar 2010<br />
    16. 16. Bridge Pattern– Guidelines (1/2)<br />You can:<br />Identify that there are operations that do not always need to be implemented in the same way.<br />© Prafulla Paraskar 2010<br />
    17. 17. Bridge Pattern– Guidelines (2/2)<br />You want to:<br />Completely hide implementations from client.<br />Avoid binding an implementation to an abstraction directly.<br />Change an implementation without even recompiling an abstraction.<br />Combine different parts of a system at runtime.<br />© Prafulla Paraskar 2010<br />
    18. 18. Thank you!<br /><br />Presentation by Prafulla Paraskar<br />© 2010 Prafulla Paraskar<br />