{"id":3902,"date":"2026-04-01T06:58:30","date_gmt":"2026-04-01T04:58:30","guid":{"rendered":"https:\/\/rock-the-prototype.com\/%category%\/adapter-pattern\/"},"modified":"2023-12-10T19:27:22","modified_gmt":"2023-12-10T18:27:22","slug":"adapter-pattern","status":"publish","type":"encyclopedia","link":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/","title":{"rendered":"Adapter Pattern"},"content":{"rendered":"<p><\/p><div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-1 fusion-flex-container nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\"><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1144px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-0 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:0px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-1\"><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Inhaltsverzeichnis<\/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: #ffffff;color:#ffffff\" 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: #ffffff;color:#ffffff\" 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=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#What_is_an_adapter_pattern\" >What is an adapter pattern?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#Do_you_want_to_know_how_the_Adapter_Pattern_works\" >Do you want to know how the Adapter Pattern works?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#How_does_the_Adapter_Pattern_work\" >How does the Adapter Pattern work?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#Components_of_the_adapter_pattern\" >Components of the adapter pattern<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#1_Target\" >1. Target<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#2_Adaptee\" >2. Adaptee<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#3_Adapter\" >3. Adapter<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#Application_example_illustrating_the_adapter_design_pattern\" >Application example illustrating the adapter design pattern:<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#Basic_principle_adapter_class\" >Basic principle adapter class<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#Code_example_for_the_implementation_of_the_adapter_pattern\" >Code example for the implementation of the adapter pattern<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#Code_example_in_JavaScript\" >Code example in JavaScript<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#Summary\" >Summary<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#2_Approaches_to_implementing_this_design_pattern\" >2 Approaches to implementing this design pattern<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#Code_reusability\" >Code reusability<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#When_this_design_pattern_does_not_fit%E2%80%A6\" >When this design pattern does not fit&#8230;<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"What_is_an_adapter_pattern\"><\/span>What is an adapter pattern?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <strong><a href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/\" target=\"_blank\" title=\"The Adapter Pattern is a structural design pattern for software that allows objects with incompatible interfaces to work together. It converts the interface of a class into another interface so that this API then meets the functional requirements and is easily maintainable without changing the source code of the original class. The properties of the Adapter Pattern are always very useful when an API to be adapted is not within the sphere of influence of the software to be changed.\" class=\"encyclopedia\">Adapter Pattern<\/a><\/strong> &#129513; is a structural <a href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/design-pattern\/\" target=\"_blank\" title=\"A design pattern is a design pattern for software as an abstract description. In programming, design patterns are usually object-oriented code drafts. Design patterns solve a class of problems.\" class=\"encyclopedia\">design pattern<\/a> for software that allows objects with incompatible interfaces to work together. It converts the interface of one class into another interface so that this API then fulfills the functional requirements and is easily maintainable without changing the source code of the original class.&#128260;&#128187;<\/p>\n<div id=\"attachment_3009\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3009\" class=\"size-medium wp-image-3009\" src=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter_Pattern-300x177.jpg\" alt=\"Adapter Pattern - Design Pattern f&uuml;r Software Architektur\" width=\"300\" height=\"177\" srcset=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter_Pattern-200x118.jpg 200w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter_Pattern-300x177.jpg 300w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter_Pattern-400x237.jpg 400w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter_Pattern-600x355.jpg 600w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter_Pattern-768x454.jpg 768w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter_Pattern-800x473.jpg 800w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter_Pattern-1024x606.jpg 1024w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter_Pattern-1200x710.jpg 1200w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter_Pattern.jpg 1224w\" sizes=\"(max-width: 300px) 100vw, 300px\"><p id=\"caption-attachment-3009\" class=\"wp-caption-text\">Adapter Pattern &ndash; Design Pattern for Software Architecture<\/p><\/div>\n<p class=\"p1\">&#9881;&#65039; The capabilities of this design pattern come into play when you need to adapt an API that is outside the scope of the software you are working on. So it helps you by bridging the gap between incompatible interfaces and making your development smoother and more efficient. &#128640;&#128279;<\/p>\n\n<h2><span class=\"ez-toc-section\" id=\"Do_you_want_to_know_how_the_Adapter_Pattern_works\"><\/span>Do you want to know how the Adapter Pattern works?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p class=\"p1\">&#128270; Curious about how this coding pattern works? Let&rsquo;s dive in! &#129343; The main idea behind this design pattern is to create a class &ndash; the adapter &ndash; that sits between two incompatible interfaces and translates requests from one interface to the other. &#128260;&#128268;<\/p>\n<p class=\"p1\">&#128161; The adapter takes an object that has the desired interface but cannot be used directly by the client and adapts it to the interface that the client expects. It is something like a language translator for your code, ensuring effective communication between different components. &#128483;&#65039;&#128170;<\/p>\n<div id=\"attachment_3841\" style=\"width: 1034px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3841\" class=\"wp-image-3841 size-full\" src=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Entwurfsmuster-Translator-Adapter-Pattern.jpg\" alt=\"Adapter Entwurfsmuster - Translator - Adapter Pattern\" width=\"1024\" height=\"1024\" srcset=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Entwurfsmuster-Translator-Adapter-Pattern-66x66.jpg 66w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Entwurfsmuster-Translator-Adapter-Pattern-150x150.jpg 150w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Entwurfsmuster-Translator-Adapter-Pattern-200x200.jpg 200w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Entwurfsmuster-Translator-Adapter-Pattern-300x300.jpg 300w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Entwurfsmuster-Translator-Adapter-Pattern-400x400.jpg 400w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Entwurfsmuster-Translator-Adapter-Pattern-600x600.jpg 600w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Entwurfsmuster-Translator-Adapter-Pattern-768x768.jpg 768w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Entwurfsmuster-Translator-Adapter-Pattern-800x800.jpg 800w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Entwurfsmuster-Translator-Adapter-Pattern.jpg 1024w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><p id=\"caption-attachment-3841\" class=\"wp-caption-text\">Adapter Design Pattern &ndash; Translator &ndash; Adapter Pattern<\/p><\/div>\n<p class=\"p1\">&#127775; So the next time you encounter incompatible interfaces, just think of the Adapter Pattern as your trusted ally! It allows you to seamlessly integrate different components and maintain a robust and flexible code base. &#127760;&#128268;<\/p>\n<p>Diese Eigenschaften des <strong>Adapter Pattern<\/strong> sind immer dann sehr n&uuml;tzlich, wenn eine anzupassende API nicht im Einflussbereich der zu &auml;ndernder Software liegt.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_does_the_Adapter_Pattern_work\"><\/span>How does the Adapter Pattern work?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The main idea behind the adapter design pattern is to create a class &ndash; the adapter &ndash; that sits between two incompatible interfaces and translates requests from one interface to the other.<\/p>\n<p>The adapter takes an object that has the desired interface but cannot be used directly by the client and adapts it to the interface that the client expects.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Components_of_the_adapter_pattern\"><\/span>Components of the adapter pattern<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"1_Target\"><\/span>1. Target<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>This is the interface that the client expects to work with. The client interacts with this interface to get the desired results.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Adaptee\"><\/span>2. Adaptee<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>This is the existing class that needs to be adapted to work with the target interface. It has an incompatible interface with the client.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3_Adapter\"><\/span>3. Adapter<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>This is the class that adapts the adaptee to work with the target interface. It implements the target interface and communicates with the adaptee to perform the desired actions.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Application_example_illustrating_the_adapter_design_pattern\"><\/span>Application example illustrating the adapter design pattern:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Suppose we have a client that uses a third-party <a href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/library\/\" target=\"_blank\" title=\"A library refers to a software library as a ready-made collection of code that can be used to perform general software development tasks. Libraries are essentially a collection of functions and procedures that can be called up by other software programs to execute certain functions.\" class=\"encyclopedia\">library<\/a> to print text to the console. The library has a method called printText that takes a string as an argument and prints it to the console. However, the client wants to use a different library that has a method called <em>displayText<\/em> to achieve the same result.<\/p>\n<p>The <em>displayText<\/em> method also takes a string as an argument and outputs it to the console, but it has a different method signature than the <em>printText<\/em> method.<\/p>\n<p>To solve this problem, we can create an adapter class that implements the Target interface (i.e. displayText) and communicates with the <strong>adaptee<\/strong> (i.e. the third-party library) to perform the desired action,<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Basic_principle_adapter_class\"><\/span>Basic principle adapter class<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The <strong>adapter class<\/strong> would have a method called displayText that takes a string as an argument, calls the third-party library&rsquo;s printText method with the same argument, and achieves the desired result.<\/p>\n<p>Consequently, the adapter pattern allows objects with incompatible interfaces to work together by creating an adapter class that translates requests from one interface to another.<\/p>\n<p>It thus provides a way to reuse existing code without modifying it, making it a powerful and flexible design pattern.<\/p>\n<div id=\"attachment_3845\" style=\"width: 1034px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3845\" class=\"wp-image-3845 size-full\" src=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adpater-Pattern-Konzept.jpg\" alt=\"Adpater-Pattern Konzept - Du merkst schon Adapter sind oft nicht einfach... \" width=\"1024\" height=\"1024\" srcset=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adpater-Pattern-Konzept-66x66.jpg 66w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adpater-Pattern-Konzept-150x150.jpg 150w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adpater-Pattern-Konzept-200x200.jpg 200w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adpater-Pattern-Konzept-300x300.jpg 300w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adpater-Pattern-Konzept-400x400.jpg 400w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adpater-Pattern-Konzept-600x600.jpg 600w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adpater-Pattern-Konzept-768x768.jpg 768w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adpater-Pattern-Konzept-800x800.jpg 800w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adpater-Pattern-Konzept.jpg 1024w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><p id=\"caption-attachment-3845\" class=\"wp-caption-text\">Adpater-Pattern Concept &ndash; You already realize that adapters are often not easy&hellip;<\/p><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Code_example_for_the_implementation_of_the_adapter_pattern\"><\/span>Code example for the implementation of the adapter pattern<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Our practical code shows you how this design pattern works and is basically structured. So you can easily understand how this coding pattern works and modify it for your purpose.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Code_example_in_JavaScript\"><\/span>Code example in JavaScript<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Here is an easy-to-understand example of implementing the adapter design pattern in JavaScript:<\/p>\n<\/div><a class=\"fusion-modal-text-link\" data-toggle=\"modal\" data-target=\".fusion-modal.Code-Beispiel f&uuml;r das Adapter Pattern in JavaScript\" href=\"#\"><script src=\"https:\/\/gist.github.com\/Sascha-Block\/cafc3abeed4651cdd87609b2065b4d77.js\"><\/script><\/a><div class=\"fusion-text fusion-text-2\"><p>In this <a href=\"https:\/\/rock-the-prototype.com\/programmiersprachen-frameworks\/javascript\/\" target=\"_blank\" rel=\"noopener\"><strong>Java Script<\/strong><\/a> <strong>code sample<\/strong>, we have an <strong>Adaptee class<\/strong> called <em>ThirdPartyLibrary<\/em> that has a printText <strong>method<\/strong> that <em>prints text<\/em> to the console. We want to use this class with a <strong>target interface<\/strong> called <em>TextPrinter<\/em>, which has a <strong>method<\/strong> <em>displayText<\/em> that also outputs text to the console.<\/p>\n<p><strong>To allow these two classes to work together<\/strong>, we create an <strong>adapter class<\/strong> called <em>TextPrinterAdapter<\/em> that implements the <em>TextPrinte<\/em>r <strong>interface<\/strong> and receives an <strong>instance<\/strong> of the <em>ThirdPartyLibrary<\/em> <strong>class<\/strong> as a <strong>constructor parameter<\/strong>. In the <em>displayText method<\/em> of the adapter, we call the <em>printText method<\/em> of the <strong>ThirdPartyLibrary instance<\/strong> to achieve the same result.<\/p>\n<p>Finally, in the client code, we create an instance of the <strong>ThirdPartyLibrary class<\/strong> and an <strong>instance of the TextPrinterAdapter class<\/strong> and pass the <strong>ThirdPartyLibrary instance as a parameter<\/strong> to the <strong>constructor of the adapter<\/strong>.<\/p>\n<p>Then we call the <em>displayText method<\/em> of the adapter with our text, and it prints the text to the console using the <em>printText method<\/em> of the <em>ThirdPartyLibrary instance<\/em>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In software development, there is often the problem that two systems or classes cannot interact directly with each other because they use different interfaces or interfaces. This is where a particular design pattern comes into play, serving as a bridge between these incompatible systems. This pattern is known as the &ldquo;<strong>Adapter Pattern<\/strong>&ldquo;.<\/p>\n<p>Imagine you have an electronic device that you want to use in another country. Unfortunately, the plug of the device does not fit into the socket of the country. Here you need a socket adapter to fix the problem. This real-world example perfectly illustrates how the corresponding design pattern works in software development. It allows two different systems to interoperate by modifying the interface of one system so that it can be understood by another without requiring changes to the original system.<\/p>\n<div id=\"attachment_3844\" style=\"width: 1034px\" class=\"wp-caption alignnone\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3844\" class=\"wp-image-3843 size-full\" src=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-echter-Adapter-Steckdosenadapter.jpg\" alt=\"This way you are guaranteed to remember what the Adapter Pattern is. Real Adapter - Socket Adapter - Rock the Prototype - Learn to program.\" width=\"1024\" height=\"1024\" srcset=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-echter-Adapter-Steckdosenadapter-66x66.jpg 66w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-echter-Adapter-Steckdosenadapter-150x150.jpg 150w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-echter-Adapter-Steckdosenadapter-200x200.jpg 200w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-echter-Adapter-Steckdosenadapter-300x300.jpg 300w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-echter-Adapter-Steckdosenadapter-400x400.jpg 400w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-echter-Adapter-Steckdosenadapter-600x600.jpg 600w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-echter-Adapter-Steckdosenadapter-768x768.jpg 768w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-echter-Adapter-Steckdosenadapter-800x800.jpg 800w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-echter-Adapter-Steckdosenadapter.jpg 1024w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><p id=\"caption-attachment-3844\" class=\"wp-caption-text\">This way you are guaranteed to remember what the adapter pattern is. Real Adapter &ndash; Socket Adapter &ndash; Rock the Prototype &ndash; Learn to program.<\/p><\/div>\n<p>The central actor in this pattern is the so-called <strong>adapter<\/strong>. This acts as an intermediary between the client and the service that the client wants to use but cannot call directly due to interface differences. The adapter translates the client&rsquo;s requests into a format that the service can understand, enabling interaction.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_Approaches_to_implementing_this_design_pattern\"><\/span>2 Approaches to implementing this design pattern<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>There are two common approaches to implementing this pattern: the <strong>class adapter<\/strong> and the <strong>object adapter.<\/strong> The class adapter uses multiple inheritance to inherit both the client and service interfaces. However, this approach has its limitations, especially in languages that do not support multiple inheritance. The object adapter, on the other hand, uses composition and holds a reference to an object of the service. This approach is more flexible and more commonly used.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Code_reusability\"><\/span><strong>Code reusability<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Another important aspect of this pattern is its impact on <strong>code reusability<\/strong>. Often developers face the challenge of reusing existing code in new projects, but encounter compatibility issues. The aforementioned pattern can provide an effective solution here, as it allows existing code to be used in a new context without having to change it.<\/p>\n<h3>When this design pattern does not fit&hellip;<\/h3>\n<p>However, there are situations when the application of the pattern is not ideal. If there are only a few <strong>incompatible interfaces<\/strong> and there is little likelihood that more will be added, the implementation of the adapter may seem overly complex. It is always advisable to consider the specific requirements and context of a project before deciding to use a particular design pattern.<\/p>\n<p>In conclusion, we can say that the pattern is a <strong>valuable <a href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/programming\/\" target=\"_blank\" title=\"What is programming? When programming, a programmer creates a software program that can run on a machine. The code is created in one of the formally defined computer languages - which are countless, such as Java, PHP, C++ or C#, Perl and many many more.\" class=\"encyclopedia\">programming<\/a> technique<\/strong> in the toolbox of any software developer. It promotes software reusability, modularity and extensibility and is a key concept for the development of flexible and maintainable systems. In an ever-changing technology landscape, where the integration of different systems is becoming increasingly important, the adapter principle remains an indispensable tool for developers.<\/p>\n<\/div><\/div><\/div><\/div><\/div><div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-2 fusion-flex-container has-pattern-background has-mask-background nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\"><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1144px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-1 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:0px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><a class=\"fusion-modal-text-link\" data-toggle=\"modal\" data-target=\".fusion-modal.Rock the Prototype - Software development &amp; Prototyping Podcast iTunes\" href=\"#\"><iframe id=\"embedPlayer\" style=\"width: 100%; max-width: 660px; overflow: hidden; border-radius: 10px; transform: translateZ(0px); animation: 2s ease 0s 6 normal none running loading-indicator; background-color: #e4e4e4;\" src=\"https:\/\/embed.podcasts.apple.com\/us\/podcast\/rock-the-prototype-software-development-prototyping\/id1684835330?itsct=podcast_box_player&amp;itscg=30200&amp;ls=1&amp;theme=auto\" height=\"450px\" frameborder=\"0\" sandbox=\"allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation-by-user-activation\"><\/iframe><\/a><\/div><\/div><\/div><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>The Adapter Pattern is a structural design pattern for software that allows objects with incompatible interfaces to work together. It converts the interface of a class into another interface so that this API then meets the functional requirements and is easily maintainable without changing the source code of the original class. The properties of the Adapter Pattern are always very useful when an API to be adapted is not within the sphere of influence of the software to be changed.<\/p>\n","protected":false},"author":1,"featured_media":3840,"template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[1258],"tags":[1144,1145,1468,1467,1169,1464,1142,1143,1465,1147,1261,1148,1466],"class_list":["post-3902","encyclopedia","type-encyclopedia","status-publish","has-post-thumbnail","hentry","category-learn-programming","tag-design-pattern-en","tag-design-pattern-en-2","tag-interface-programming","tag-interfaces-en","tag-javascript-en","tag-object-orientation","tag-programming","tag-programming-en","tag-programming-interface","tag-software-architecture","tag-software-architecture-en","tag-software-development","tag-software-interfaces"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Adapter Pattern - Software Development: Advantages of Adapter Patterns<\/title>\n<meta name=\"description\" content=\"How do Adapter Patterns work? \u2705 Make interfaces &amp; APIs compatible \u2705 Clever software design with proven design pattern \u2705\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adapter Pattern - Software Development: Advantages of Adapter Patterns\" \/>\n<meta property=\"og:description\" content=\"How do Adapter Patterns work? \u2705 Make interfaces &amp; APIs compatible \u2705 Clever software design with proven design pattern \u2705\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/\" \/>\n<meta property=\"og:site_name\" content=\"Rock the Prototype - Softwareentwicklung &amp; Prototyping\" \/>\n<meta property=\"og:image\" content=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-Adapter-Entwurfsmuster-Programmieren.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/adapter-pattern\\\/\",\"url\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/adapter-pattern\\\/\",\"name\":\"Adapter Pattern - Software Development: Advantages of Adapter Patterns\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/adapter-pattern\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/adapter-pattern\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rock-the-prototype.com\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/Adapter-Pattern-Adapter-Entwurfsmuster-Programmieren.jpg\",\"datePublished\":\"2026-04-01T04:58:30+00:00\",\"description\":\"How do Adapter Patterns work? \u2705 Make interfaces & APIs compatible \u2705 Clever software design with proven design pattern \u2705\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/adapter-pattern\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/adapter-pattern\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/adapter-pattern\\\/#primaryimage\",\"url\":\"https:\\\/\\\/rock-the-prototype.com\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/Adapter-Pattern-Adapter-Entwurfsmuster-Programmieren.jpg\",\"contentUrl\":\"https:\\\/\\\/rock-the-prototype.com\\\/wp-content\\\/uploads\\\/2023\\\/03\\\/Adapter-Pattern-Adapter-Entwurfsmuster-Programmieren.jpg\",\"width\":1024,\"height\":1024,\"caption\":\"Adapter Pattern - Adapter Entwurfsmuster Programmieren lernen\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/adapter-pattern\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Startseite\",\"item\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/rock-the-prototype\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Prototyping Wiki\",\"item\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/wiki\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Adapter Pattern\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/\",\"name\":\"Rock the Prototype - Softwareentwicklung &amp; Prototyping\",\"description\":\"Prototyping: Software Prototypen, Software entwickeln &amp; Programmieren im Team\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Adapter Pattern - Software Development: Advantages of Adapter Patterns","description":"How do Adapter Patterns work? \u2705 Make interfaces & APIs compatible \u2705 Clever software design with proven design pattern \u2705","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/","og_locale":"en_US","og_type":"article","og_title":"Adapter Pattern - Software Development: Advantages of Adapter Patterns","og_description":"How do Adapter Patterns work? \u2705 Make interfaces & APIs compatible \u2705 Clever software design with proven design pattern \u2705","og_url":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/","og_site_name":"Rock the Prototype - Softwareentwicklung &amp; Prototyping","og_image":[{"width":1024,"height":1024,"url":"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-Adapter-Entwurfsmuster-Programmieren.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/","url":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/","name":"Adapter Pattern - Software Development: Advantages of Adapter Patterns","isPartOf":{"@id":"https:\/\/rock-the-prototype.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#primaryimage"},"image":{"@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#primaryimage"},"thumbnailUrl":"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-Adapter-Entwurfsmuster-Programmieren.jpg","datePublished":"2026-04-01T04:58:30+00:00","description":"How do Adapter Patterns work? \u2705 Make interfaces & APIs compatible \u2705 Clever software design with proven design pattern \u2705","breadcrumb":{"@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#primaryimage","url":"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-Adapter-Entwurfsmuster-Programmieren.jpg","contentUrl":"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/03\/Adapter-Pattern-Adapter-Entwurfsmuster-Programmieren.jpg","width":1024,"height":1024,"caption":"Adapter Pattern - Adapter Entwurfsmuster Programmieren lernen"},{"@type":"BreadcrumbList","@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/adapter-pattern\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Startseite","item":"https:\/\/rock-the-prototype.com\/en\/rock-the-prototype\/"},{"@type":"ListItem","position":2,"name":"Prototyping Wiki","item":"https:\/\/rock-the-prototype.com\/en\/wiki\/"},{"@type":"ListItem","position":3,"name":"Adapter Pattern"}]},{"@type":"WebSite","@id":"https:\/\/rock-the-prototype.com\/en\/#website","url":"https:\/\/rock-the-prototype.com\/en\/","name":"Rock the Prototype - Softwareentwicklung &amp; Prototyping","description":"Prototyping: Software Prototypen, Software entwickeln &amp; Programmieren im Team","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rock-the-prototype.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/encyclopedia\/3902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/encyclopedia"}],"about":[{"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/types\/encyclopedia"}],"author":[{"embeddable":true,"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/users\/1"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/media\/3840"}],"wp:attachment":[{"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/media?parent=3902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/categories?post=3902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/tags?post=3902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}