{"id":3303,"date":"2020-11-27T09:35:42","date_gmt":"2020-11-27T09:35:42","guid":{"rendered":"https:\/\/eluminoustechnologies.com\/blog\/?p=3303"},"modified":"2025-05-22T10:11:04","modified_gmt":"2025-05-22T10:11:04","slug":"adapter-design-pattern","status":"publish","type":"post","link":"https:\/\/eluminoustechnologies.com\/blog\/adapter-design-pattern\/","title":{"rendered":"Understanding Adapter Design Pattern with a Case Study"},"content":{"rendered":"<p>Have you ever thrown up your hands in frustration when after a hectic day of travel, you find your phone&#8217;s charger is incompatible with the power adapter in your hotel room?<\/p>\n<p>Yes!<\/p>\n<p>Then you can understand the feeling of a developer when issues arise during developing software whereby two objects with different interfaces in the code need to interact with each other.<\/p>\n<p>The challenge in both cases is to find a solution that costs less.<\/p>\n<p><em>i) In your case- buying a new compatible power adapter<\/em><\/p>\n<p><em>ii) In the developers&#8217; case- reworking the code because the changes broke something.<\/em><\/p>\n<p>The real-time solution in each case is the power adapter; one is physical while the other is virtual.<\/p>\n<p>In this blog, we will understand the adapter design pattern and how it deals with incompatible class issues.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"#\" data-href=\"https:\/\/eluminoustechnologies.com\/blog\/adapter-design-pattern\/#what-is-adapter-design-pattern\" >What is Adapter Design Pattern?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"#\" data-href=\"https:\/\/eluminoustechnologies.com\/blog\/adapter-design-pattern\/#what-are-the-types-of-adapter-design-patterns\" >What are the Types of Adapter Design Patterns?\u00a0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"#\" data-href=\"https:\/\/eluminoustechnologies.com\/blog\/adapter-design-pattern\/#case-study-of-adapter-design-pattern\" >Case Study of Adapter Design Pattern\u00a0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"#\" data-href=\"https:\/\/eluminoustechnologies.com\/blog\/adapter-design-pattern\/#pros-and-cons-of-adapter-design-pattern\" >Pros and Cons of Adapter Design Pattern\u00a0<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"what-is-adapter-design-pattern\"><\/span><strong>What is Adapter Design Pattern?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The adapter design pattern belongs to the structural category of software design patterns. Structural design patterns deal with the composition of classes and objects in code. The adapter pattern, as such, presents a way to convert an object into another object that the client expects.<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-4529 lazyload\" data-src=\"https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-16.png?lossy=2&strip=1&webp=1\" alt=\"What is Adapter Design Pattern?\" width=\"900\" height=\"450\" title=\"\" data-srcset=\"https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-16.png?lossy=2&amp;strip=1&amp;webp=1 900w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-16.png?size=128x64&amp;lossy=2&amp;strip=1&amp;webp=1 128w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-16.png?size=256x128&amp;lossy=2&amp;strip=1&amp;webp=1 256w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-16.png?size=384x192&amp;lossy=2&amp;strip=1&amp;webp=1 384w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-16.png?size=512x256&amp;lossy=2&amp;strip=1&amp;webp=1 512w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-16.png?size=640x320&amp;lossy=2&amp;strip=1&amp;webp=1 640w\" data-sizes=\"auto\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 900px; --smush-placeholder-aspect-ratio: 900\/450;\" data-original-sizes=\"(max-width: 900px) 100vw, 900px\"><\/p>\n<p>It does this by adapting one object to another object. This allows objects with different class interfaces to work together seamlessly. Like its physical counterpart, the software adapter pattern doesn&#8217;t add any extra functionality to the interfaces of the objects in question (a travel USB adapter charger doesn&#8217;t physically alter either the phone&#8217;s charging point or the plug point).<\/p>\n<p><span class=\"TextRun SCXW265863451 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW265863451 BCX9\">Let\u2019s understand the adapter design pattern with the help of a <\/span><\/span><span class=\"TextRun SCXW265863451 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW265863451 BCX9\">real-world<\/span><\/span><span class=\"TextRun SCXW265863451 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW265863451 BCX9\"> example of a travel charger.<\/span><\/span><span class=\"EOP SCXW265863451 BCX9\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h3 aria-level=\"3\"><strong>Travel Charger\u00a0<\/strong><\/h3>\n<p><span data-contrast=\"auto\">Rather, it simply converts the interface of one object to that of another object. This makes it different from the decorator design pattern, which adds new functionality to an existing object&#8217;s interface. The adapter pattern, as such, doesn&#8217;t change the object&#8217;s existing interface. <\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Again, as with real-life Adapters, the client (i.e., user) cannot see the complex conversion executed by an Adapter as it completely wraps an object. The latter isn&#8217;t even aware that the adapter wraps it. For example, an object that functions in grams and kilograms can be wrapped with an adapter that converts such data to the imperial units of ounces and pounds.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/strong><\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-3306 aligncenter lazyload\" data-src=\"https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/Adapter-Design-Pattern-UML-Diagram.png?lossy=2&strip=1&webp=1\" alt=\"Adapter-Design-Pattern-UML-Diagram\" width=\"386\" height=\"277\" title=\"\" data-srcset=\"https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/Adapter-Design-Pattern-UML-Diagram.png?lossy=2&amp;strip=1&amp;webp=1 386w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/Adapter-Design-Pattern-UML-Diagram.png?size=128x92&amp;lossy=2&amp;strip=1&amp;webp=1 128w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/Adapter-Design-Pattern-UML-Diagram.png?size=256x184&amp;lossy=2&amp;strip=1&amp;webp=1 256w\" data-sizes=\"auto\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 386px; --smush-placeholder-aspect-ratio: 386\/277;\" data-original-sizes=\"(max-width: 386px) 100vw, 386px\"><\/p>\n<p><strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Adapter Design Pattern UML Diagram<\/strong><\/p>\n<p><span class=\"TextRun SCXW130932985 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW130932985 BCX9\">As this diagram shows, the Adapter gets an interface of class that is compatible with an existing object (i.e., the client). The client then uses this interface to call the Adapter&#8217;s method (i.e., to execute a function). Once it receives this call, the Adapter passes on the request to the other object (i.e., <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW130932985 BCX9\">Adaptee<\/span><span class=\"NormalTextRun SCXW130932985 BCX9\">), but in the manner it expects.<\/span><\/span><span class=\"EOP SCXW130932985 BCX9\" data-ccp-props=\"{&quot;201341983&quot;:1,&quot;335551550&quot;:1,&quot;335551620&quot;:1,&quot;335559739&quot;:160,&quot;335559740&quot;:450}\">\u00a0<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"what-are-the-types-of-adapter-design-patterns\"><\/span><strong><span class=\"TextRun SCXW124277331 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW124277331 BCX9\" data-ccp-parastyle=\"heading 2\">What are the Types of Adapter Design Patterns?<\/span><\/span><span class=\"EOP SCXW124277331 BCX9\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img decoding=\"async\" class=\"size-full wp-image-4527 lazyload\" data-src=\"https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-14.png?lossy=2&strip=1&webp=1\" alt=\"What are the Types of Adapter Design Pattern?\u00a0\" width=\"900\" height=\"450\" title=\"\" data-srcset=\"https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-14.png?lossy=2&amp;strip=1&amp;webp=1 900w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-14.png?size=128x64&amp;lossy=2&amp;strip=1&amp;webp=1 128w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-14.png?size=256x128&amp;lossy=2&amp;strip=1&amp;webp=1 256w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-14.png?size=384x192&amp;lossy=2&amp;strip=1&amp;webp=1 384w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-14.png?size=512x256&amp;lossy=2&amp;strip=1&amp;webp=1 512w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-14.png?size=640x320&amp;lossy=2&amp;strip=1&amp;webp=1 640w\" data-sizes=\"auto\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 900px; --smush-placeholder-aspect-ratio: 900\/450;\" data-original-sizes=\"(max-width: 900px) 100vw, 900px\"><\/p>\n<h3><strong>There are two types of adapter patterns,\u00a0\u00a0<\/strong><\/h3>\n<ol>\n<li data-leveltext=\"%1.\" data-font=\"Calibri\" data-listid=\"3\" data-list-defn-props=\"{&quot;335552541&quot;:0,&quot;335559683&quot;:0,&quot;335559684&quot;:-1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769242&quot;:[65533,0,46],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;%1.&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"none\"><strong>\u00a0Object adapter pattern<\/strong>\u00a0<\/span><span data-contrast=\"none\">\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<\/ol>\n<p><span data-contrast=\"none\">The object adapter can be used in all programming languages. Based on the composition principle, the adapter wraps one object while implementing the interface of the other object.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<ol>\n<li data-leveltext=\"%1.\" data-font=\"Calibri\" data-listid=\"3\" data-list-defn-props=\"{&quot;335552541&quot;:0,&quot;335559683&quot;:0,&quot;335559684&quot;:-1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769242&quot;:[65533,0,46],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;%1.&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><strong>Class adapter pattern\u00a0\u00a0\u00a0<\/strong><\/li>\n<\/ol>\n<p><span data-contrast=\"none\">The class adapter can be used only with languages compatible with multiple inheritances, e.g., C++. The adapter inherits the interfaces from both objects simultaneously based on multiple inheritances.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">Moreover, composition allows for greater flexibility, making it easier to change your existing code without breaking something else. Hence the object adapter pattern is the more widely used method of the two.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2 aria-level=\"2\"><span class=\"ez-toc-section\" id=\"case-study-of-adapter-design-pattern\"><\/span><strong>Case Study of Adapter Design Pattern\u00a0<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><span data-contrast=\"none\">As a\u00a0<\/span><a href=\"https:\/\/eluminoustechnologies.com\/web-application-development\" target=\"_blank\" rel=\"noopener\"><span data-contrast=\"none\">custom web application development company<\/span><\/a><span data-contrast=\"none\">, we had the opportunity to use the adapter design pattern for a very unique real-life problem brought to us by a client.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h4><b><span data-contrast=\"none\">Client Background\u00a0<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h4>\n<p><span data-contrast=\"none\">The client was based in the UK and operated a business renting parking spaces. Seeing how expensive and full of hassle it was to land a nice parking space, the client approached malls and large shopping centers to rent their unused parking spaces. This win-win situation enabled our clients to allocate all the unused parking spaces to their clients. <\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h4><b><span data-contrast=\"none\">Challenges\u00a0<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h4>\n<p><span data-contrast=\"none\">The task in front of us was to develop a system that reads the parking data from different parking spaces and uses it to bill a client based on their usage.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">However, there was a challenge as each parking area used a different MS Excel format. And by different, we don\u2019t mean just different column names. Every little thing, from the data placement to the data type, was entirely different for each parking area.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h4><b><span data-contrast=\"none\">The solution was obvious \u2013 use an Adapter Design Pattern.\u00a0<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h4>\n<p><span data-contrast=\"none\">We used adapters to reconcile all these differences in data, helping create a system that seamlessly read data from different source formats and used it to bill the user.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"pros-and-cons-of-adapter-design-pattern\"><\/span><strong><span class=\"TextRun SCXW31537959 BCX9\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW31537959 BCX9\" data-ccp-parastyle=\"heading 2\">Pros and Cons of Adapter Design Pattern<\/span><\/span><span class=\"EOP SCXW31537959 BCX9\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img decoding=\"async\" class=\"size-full wp-image-4528 lazyload\" data-src=\"https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-15.png?lossy=2&strip=1&webp=1\" alt=\"Pros and Cons of Adapter Design Pattern\u00a0\" width=\"900\" height=\"450\" title=\"\" data-srcset=\"https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-15.png?lossy=2&amp;strip=1&amp;webp=1 900w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-15.png?size=128x64&amp;lossy=2&amp;strip=1&amp;webp=1 128w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-15.png?size=256x128&amp;lossy=2&amp;strip=1&amp;webp=1 256w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-15.png?size=384x192&amp;lossy=2&amp;strip=1&amp;webp=1 384w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-15.png?size=512x256&amp;lossy=2&amp;strip=1&amp;webp=1 512w, https:\/\/b4130876.smushcdn.com\/4130876\/wp-content\/uploads\/2020\/11\/MicrosoftTeams-image-15.png?size=640x320&amp;lossy=2&amp;strip=1&amp;webp=1 640w\" data-sizes=\"auto\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 900px; --smush-placeholder-aspect-ratio: 900\/450;\" data-original-sizes=\"(max-width: 900px) 100vw, 900px\"><\/p>\n<h3 aria-level=\"3\"><strong>Pros of Adapter Design Pattern\u00a0<\/strong><\/h3>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"5\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559683&quot;:0,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"none\">Because it adheres to the open\/closed principle, you can add newer types of adapters to the code without breaking your existing client code.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559685&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"5\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559683&quot;:0,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><span data-contrast=\"none\">As it follows the single responsibility principle, you can separate the interface code from your application&#8217;s main business logic code.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559685&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"5\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559683&quot;:0,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"3\" data-aria-level=\"1\"><span data-contrast=\"none\">It allows for more excellent code reusability and codes flexibility.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559685&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"5\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559683&quot;:0,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"4\" data-aria-level=\"1\"><span data-contrast=\"none\">It comes to your rescue when you have to make things work together after they&#8217;ve been designed.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h3 aria-level=\"3\"><span data-contrast=\"none\">Cons of Adapter Design Pattern<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h3>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"4\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559683&quot;:0,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"5\" data-aria-level=\"1\"><span data-contrast=\"none\">Code can become too complex as the adapter pattern requires the introduction of new classes and interfaces.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:1,&quot;335551550&quot;:1,&quot;335551620&quot;:1,&quot;335559739&quot;:160,&quot;335559740&quot;:450}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"4\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559683&quot;:0,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"6\" data-aria-level=\"1\"><span data-contrast=\"none\">As each client request is forwarded, it might affect the overall performance.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:1,&quot;335551550&quot;:1,&quot;335551620&quot;:1,&quot;335559739&quot;:160,&quot;335559740&quot;:450}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:1,&quot;335551550&quot;:1,&quot;335551620&quot;:1,&quot;335559685&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:450}\">\u00a0<\/span><strong>When to Use Adapter Design Pattern?\u00a0<\/strong><\/p>\n<p><span data-contrast=\"none\">Adapter design patterns can be used when,<\/span><span data-ccp-props=\"{&quot;201341983&quot;:1,&quot;335551550&quot;:1,&quot;335551620&quot;:1,&quot;335559739&quot;:160,&quot;335559740&quot;:450}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"4\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559683&quot;:0,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"7\" data-aria-level=\"1\"><span data-contrast=\"none\">you want to use an existing<\/span><b><span data-contrast=\"none\"> interface of class<\/span><\/b><span data-contrast=\"none\">\u00a0that is not compatible with the one you need.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:1,&quot;335551550&quot;:1,&quot;335551620&quot;:1,&quot;335559739&quot;:160,&quot;335559740&quot;:450}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"4\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559683&quot;:0,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"8\" data-aria-level=\"1\"><span data-contrast=\"none\">you want to create a reusable class that can be used with unrelated classes that might have incompatible interfaces.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:1,&quot;335551550&quot;:1,&quot;335551620&quot;:1,&quot;335559739&quot;:160,&quot;335559740&quot;:450}\">\u00a0<\/span><\/li>\n<\/ul>\n<h5>Also read : <a href=\"https:\/\/eluminoustechnologies.com\/blog\/observer-design-pattern-case-study\/\" target=\"_blank\" rel=\"noopener\">What is Observer Design Pattern A Brief Guide with a Case Study<\/a><\/h5>\n<h3 aria-level=\"2\"><strong>Conclusion\u00a0<\/strong><\/h3>\n<p><span data-contrast=\"none\">By using the adapter design pattern, you can prevent the menace of duplicate code that often drags a project down. Instead, when confronted with classes that cannot work together because of incompatible interfaces, you can simply use adapters to keep your project on track, fast, and efficient.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">However, the challenge in such situations is more about knowing the disease and less about finding the cure. Means, you should first recognize the problem affecting your project and only then decide which software design pattern can help you move forward.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">As a\u00a0<\/span><a href=\"https:\/\/eluminoustechnologies.com\/\" target=\"_blank\" rel=\"noopener\"><span data-contrast=\"none\">Web Design &amp; Development Company<\/span><\/a><span data-contrast=\"none\">\u00a0for close to two decades, we\u2019ve successfully employed the correct design patterns to reduce the \u2018Go to market\u2019 time for our clients while keeping the underlying code efficient, maintainable, and scalable. To know the right approach for your project, get in touch with us.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span>And if you liked this post, subscribe to get informative posts about web and mobile development, data analytics, and eCommerce delivered to your inbox. Thank you for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever thrown up your hands in frustration when after a hectic day of travel, you find your phone&#8217;s charger is incompatible with the&#8230;<\/p>\n","protected":false},"author":7,"featured_media":3304,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[308,118,155],"tags":[351,350,241,352],"class_list":["post-3303","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-it-services-for-enterprise","category-php-development","category-web-development","tag-adapter-design-pattern","tag-custom-web-application-development-company","tag-hire-dedicated-developer","tag-web-design-development-company"],"acf":[],"_links":{"self":[{"href":"https:\/\/eluminoustechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eluminoustechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eluminoustechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eluminoustechnologies.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/eluminoustechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=3303"}],"version-history":[{"count":0,"href":"https:\/\/eluminoustechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3303\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eluminoustechnologies.com\/blog\/wp-json\/wp\/v2\/media\/3304"}],"wp:attachment":[{"href":"https:\/\/eluminoustechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=3303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eluminoustechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=3303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eluminoustechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=3303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}