{"id":36,"date":"2009-03-12T00:15:00","date_gmt":"2009-03-12T00:15:00","guid":{"rendered":"https:\/\/karwin.com\/blog\/index.php\/2009\/03\/12\/how-do-the-proxy-decorator-adaptor-and-bridge-patterns-differ\/"},"modified":"2009-03-12T00:15:00","modified_gmt":"2009-03-12T00:15:00","slug":"how-do-the-proxy-decorator-adaptor-and-bridge-patterns-differ","status":"publish","type":"post","link":"https:\/\/karwin.com\/blog\/index.php\/2009\/03\/12\/how-do-the-proxy-decorator-adaptor-and-bridge-patterns-differ\/","title":{"rendered":"How do the Proxy, Decorator, Adaptor, and Bridge Patterns differ?"},"content":{"rendered":"<p>A user recently <a href=\"http:\/\/stackoverflow.com\/questions\/350404\/how-do-the-proxy-decorator-adaptor-and-bridge-patterns-differ\/\">asked<\/a>:<\/p>\n<blockquote><p>I was looking at the Proxy Pattern, and to me it seems an awful lot like the Decorator, Adaptor, and Bridge Patterns. Am I misunderstanding something? What&#8217;s the difference? Why would I use the proxy pattern veses the others? How have you used them in the past in real world projects?<\/p><\/blockquote>\n<p>Proxy, Decorator, Adapter, and Bridge are all variations on &#8220;wrapping&#8221; a class.  But their uses are different.<\/p>\n<div>\n<ul>\n<li><strong>Proxy<\/strong> could be used when you want to lazy-instantiate an object, or hide the fact that you&#8217;re calling a remote service, or control access to the object.<\/li>\n<li><strong>Decorator<\/strong> is also called &#8220;Smart Proxy.&#8221; This is used when you want to add functionality to an object, but not by extending that object&#8217;s type. This allows you to do so at runtime.<\/li>\n<li><strong>Adapter<\/strong> is used when you have an abstract interface, and you want to map that interface to another object which has similar functional role, but a different interface.<\/li>\n<li><strong>Bridge<\/strong> is very similar to Adapter, but we call it Bridge when you define both the abstract interface and the underlying implementation. I.e. you&#8217;re not adapting to some legacy or third-party code, you&#8217;re the designer of all the code but you need to be able to swap out different implementations.<\/li>\n<\/ul><\/div>\n<p>I&#8217;m posting to my blog the questions I&#8217;ve answered on StackOverflow, which earned the &#8220;Good Answer&#8221; badge. This was my answer to &#8220;<a href=\"http:\/\/stackoverflow.com\/questions\/350404\/how-do-the-proxy-decorator-adaptor-and-bridge-patterns-differ\/350471#350471\">How do the Proxy, Decorator, Adaptor, and Bridge Patterns differ?<\/a>&#8220;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A user recently asked: I was looking at the Proxy Pattern, and to me it seems an awful lot like the Decorator, Adaptor, and Bridge Patterns. Am I misunderstanding something? What&#8217;s the difference? Why would I use the proxy pattern veses the others? How have you used them in the past in real world projects? [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[11,9],"tags":[],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-architecture","category-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pawgV7-A","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=36"}],"version-history":[{"count":0,"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/36\/revisions"}],"wp:attachment":[{"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/karwin.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}