<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lucas Carlos</title>
    <description>The latest articles on DEV Community by Lucas Carlos (@lucas_carlos_247b15bef594).</description>
    <link>https://dev.to/lucas_carlos_247b15bef594</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4123288%2Fa056a2b4-7e87-46bb-b0a6-17467b1e4d33.png</url>
      <title>DEV Community: Lucas Carlos</title>
      <link>https://dev.to/lucas_carlos_247b15bef594</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lucas_carlos_247b15bef594"/>
    <language>en</language>
    <item>
      <title>Adapter Pattern in Java: How to Integrate Payment Gateways Without Tight Coupling”</title>
      <dc:creator>Lucas Carlos</dc:creator>
      <pubDate>Sun, 13 Sep 2026 17:03:31 +0000</pubDate>
      <link>https://dev.to/lucas_carlos_247b15bef594/adapter-pattern-in-java-how-to-integrate-payment-gateways-without-tight-coupling-26c8</link>
      <guid>https://dev.to/lucas_carlos_247b15bef594/adapter-pattern-in-java-how-to-integrate-payment-gateways-without-tight-coupling-26c8</guid>
      <description>&lt;p&gt;Software systems rarely remain isolated.&lt;/p&gt;

&lt;p&gt;Even applications that start out simple eventually need to communicate with banks, payment gateways, email services, ERPs, shipping providers, and third-party APIs.&lt;/p&gt;

&lt;p&gt;The problem begins when each integration has a different contract and those differences start leaking directly into the application's business logic.&lt;/p&gt;

&lt;p&gt;This is exactly the kind of situation where the &lt;strong&gt;Adapter Pattern&lt;/strong&gt; becomes useful.&lt;/p&gt;

&lt;p&gt;In this article, we will explore how to apply the &lt;strong&gt;Adapter Pattern in Java&lt;/strong&gt; to a real-world scenario involving multiple payment gateways. We will analyze not only the implementation itself, but also the architectural problem that motivates the pattern, its structure, advantages, limitations, and impact on system evolution.&lt;/p&gt;




&lt;h1&gt;
  
  
  1. Fundamental Concepts
&lt;/h1&gt;

&lt;h2&gt;
  
  
  What Are Design Patterns?
&lt;/h2&gt;

&lt;p&gt;Before discussing Adapter specifically, it is important to understand what a Design Pattern actually is.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Design Pattern&lt;/strong&gt; is not ready-made code that should simply be copied into any application.&lt;/p&gt;

&lt;p&gt;Instead, it represents a reusable solution to a recurring software design problem.&lt;/p&gt;

&lt;p&gt;Throughout the development of different systems, certain architectural problems tend to appear repeatedly.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How can we create complex objects without tightly coupling the code to concrete classes?&lt;/li&gt;
&lt;li&gt;How can incompatible objects work together?&lt;/li&gt;
&lt;li&gt;How can behavior be changed at runtime?&lt;/li&gt;
&lt;li&gt;How can a class avoid depending directly on several concrete implementations?&lt;/li&gt;
&lt;li&gt;How can multiple components be notified when an event occurs?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Design Patterns provide proven ways to organize solutions to these kinds of problems.&lt;/p&gt;

&lt;p&gt;The classic patterns documented by the &lt;strong&gt;Gang of Four, or GoF&lt;/strong&gt;, are usually grouped into three main categories.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creational Patterns
&lt;/h3&gt;

&lt;p&gt;These patterns deal with object creation.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Factory Method;&lt;/li&gt;
&lt;li&gt;Abstract Factory;&lt;/li&gt;
&lt;li&gt;Builder;&lt;/li&gt;
&lt;li&gt;Singleton;&lt;/li&gt;
&lt;li&gt;Prototype.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Structural Patterns
&lt;/h3&gt;

&lt;p&gt;These patterns deal with how classes and objects are composed and connected.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adapter;&lt;/li&gt;
&lt;li&gt;Facade;&lt;/li&gt;
&lt;li&gt;Decorator;&lt;/li&gt;
&lt;li&gt;Composite;&lt;/li&gt;
&lt;li&gt;Proxy;&lt;/li&gt;
&lt;li&gt;Bridge.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Behavioral Patterns
&lt;/h3&gt;

&lt;p&gt;These patterns focus on communication and responsibility distribution between objects.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strategy;&lt;/li&gt;
&lt;li&gt;Observer;&lt;/li&gt;
&lt;li&gt;Command;&lt;/li&gt;
&lt;li&gt;State;&lt;/li&gt;
&lt;li&gt;Template Method.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The pattern discussed in this article belongs to the second category.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Is the Adapter Pattern?
&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;Adapter Pattern is a structural design pattern&lt;/strong&gt; used when two components have incompatible interfaces but still need to work together.&lt;/p&gt;

&lt;p&gt;The Adapter acts as a translation layer.&lt;/p&gt;

&lt;p&gt;Instead of modifying the entire system to understand an external component, we create an intermediate object that converts the external interface into the format expected by the application.&lt;/p&gt;

&lt;p&gt;The basic idea can be represented like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
   |
   v
Internal Interface
   |
   v
Adapter
   |
   v
External Component
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application does not need to understand how the external component works internally.&lt;/p&gt;

&lt;p&gt;It only needs to understand its own contract.&lt;/p&gt;

&lt;p&gt;The Adapter is responsible for translating calls, parameters, and responses.&lt;/p&gt;




&lt;h1&gt;
  
  
  A Simple Analogy
&lt;/h1&gt;

&lt;p&gt;A common analogy is a power outlet adapter.&lt;/p&gt;

&lt;p&gt;Imagine buying a laptop in another country.&lt;/p&gt;

&lt;p&gt;The charger works perfectly, and the electrical outlet also works perfectly.&lt;/p&gt;

&lt;p&gt;The problem is that their physical formats are incompatible.&lt;/p&gt;

&lt;p&gt;There are three possible solutions.&lt;/p&gt;

&lt;p&gt;The first would be replacing the entire electrical installation.&lt;/p&gt;

&lt;p&gt;The second would be modifying the laptop charger.&lt;/p&gt;

&lt;p&gt;The third would be placing an adapter between them.&lt;/p&gt;

&lt;p&gt;The third option is usually the simplest.&lt;/p&gt;

&lt;p&gt;The same idea can be applied to software:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Application
    |
    v
Adapter
    |
    v
External API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neither the application nor the external library necessarily needs to be rewritten.&lt;/p&gt;

&lt;p&gt;We simply create a layer capable of translating between them.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Problem Does the Adapter Pattern Solve?
&lt;/h1&gt;

&lt;p&gt;Consider an e-commerce platform.&lt;/p&gt;

&lt;p&gt;Initially, the company works with only one payment gateway called &lt;code&gt;LegacyBank&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The code could look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentService&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;LegacyBankClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;PaymentService&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LegacyBankClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;orderId&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;executeCharge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;orderId&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a very small system, this may seem completely acceptable.&lt;/p&gt;

&lt;p&gt;The problem becomes clearer when we analyze the dependency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
      |
      v
LegacyBankClient
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The business logic is directly tied to an external provider.&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;LegacyBankClient&lt;/code&gt; changes, &lt;code&gt;PaymentService&lt;/code&gt; may also need to change.&lt;/p&gt;

&lt;p&gt;If the company stops working with LegacyBank, &lt;code&gt;PaymentService&lt;/code&gt; will need to be modified.&lt;/p&gt;

&lt;p&gt;If a second provider is introduced, the code may start growing quickly.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equals&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"LEGACY_BANK"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;legacyBank&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;executeCharge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;orderId&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;doubleValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equals&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"MODERN_PAY"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;modernPay&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createPayment&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;customerId&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;orderId&lt;/span&gt;
    &lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then a third gateway is added:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equals&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"FAST_PAY"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// New integration&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then a fourth:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equals&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"GLOBAL_PAY"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Another integration&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, &lt;code&gt;PaymentService&lt;/code&gt; starts accumulating responsibilities.&lt;/p&gt;

&lt;p&gt;It is no longer responsible only for coordinating payments.&lt;/p&gt;

&lt;p&gt;It now also understands:&lt;/p&gt;

&lt;p&gt;• external contracts;&lt;br&gt;
• parameter formats;&lt;br&gt;
• authentication details;&lt;br&gt;
• response handling;&lt;br&gt;
• return codes;&lt;br&gt;
• provider-specific naming;&lt;br&gt;
• type conversions;&lt;br&gt;
• implementation details of each vendor.&lt;/p&gt;

&lt;p&gt;This significantly increases coupling.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;The Coupling Problem&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Imagine that our service knows all of this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
    |
    +-- knows how LegacyBank works
    |
    +-- knows how ModernPay works
    |
    +-- knows how FastPay works
    |
    +-- knows how GlobalPay works
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means external changes can directly affect internal business logic. For example, if &lt;code&gt;ModernPay&lt;/code&gt; changes its API from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;createPayment(...)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;authorizeTransaction(...)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;that change could directly affect our business layer.&lt;/p&gt;

&lt;p&gt;That is not ideal.&lt;/p&gt;

&lt;p&gt;A healthier architecture would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
      |
      v
PaymentGateway
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application defines the contract it wants to use. External implementation details remain outside the business logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Participants in the Adapter Pattern&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The classic Adapter Pattern includes several important participants.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Client&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Client is the code that wants to use a particular service.&lt;/p&gt;

&lt;p&gt;In our case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The service wants to process payments&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Target&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Target is the interface the Client expects to use.&lt;/p&gt;

&lt;p&gt;In our project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;PaymentGateway&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It represents the internal contract expected by the application.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Adaptee&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Adaptee is the existing class whose interface is incompatible with the system.&lt;/p&gt;

&lt;p&gt;In our case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LegacyBankClient
ModernPayClient
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These classes represent external libraries or APIs.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Adapter&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Adapter is responsible for translating between the Target and the Adaptee.&lt;/p&gt;

&lt;p&gt;We will have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LegacyBankAdapter
ModernPayAdapter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Adapter receives a call in the format used by our domain and converts it to the format expected by the external provider.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The Complete Flow&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The overall behavior can be represented like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
      |
      | calls pay()
      v
PaymentGateway
      |
      v
ModernPayAdapter
      |
      | translates PaymentRequest
      v
ModernPayClient
      |
      | calls the external API
      v
ModernPayResponse
      |
      | translates the response
      v
PaymentResult
      |
      v
PaymentService
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that translation happens in both directions.&lt;/p&gt;

&lt;p&gt;First:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Internal model -&amp;gt; External model
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;External model -&amp;gt; Internal model
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is one of the Adapter's main responsibilities.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;2. Development&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Real-World Scenario&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Imagine an e-commerce platform that processes thousands of orders. During its first few years, all payments were handled by a single provider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LegacyBank
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The initial architecture looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customer
   |
   v
Checkout
   |
   v
PaymentService
   |
   v
LegacyBank
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As long as there was only one provider, the solution worked. As the company grew, new requirements emerged.&lt;/p&gt;

&lt;p&gt;The business started demanding:&lt;/p&gt;

&lt;p&gt;• a second payment gateway;&lt;br&gt;
• the ability to compare fees;&lt;br&gt;
• redundancy in case one provider became unavailable;&lt;br&gt;
• support for new payment methods;&lt;br&gt;
• easier provider negotiation;&lt;br&gt;
• the ability to replace a provider in the future.&lt;/p&gt;

&lt;p&gt;The company then decided to integrate &lt;code&gt;ModernPay&lt;/code&gt;. The problem was that both APIs had completely different contracts.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;LegacyBank API&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The legacy gateway exposes an operation similar to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;executeCharge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;reference&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its response is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;LegacyBankResponse&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;containing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;status
transactionCode
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;ModernPay API&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The new provider uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;createPayment&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;customerId&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;BigDecimal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;orderId&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;ModernPayResponse&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;containing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;successful
paymentId
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both APIs serve the same business purpose:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;process a payment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But their contracts are completely different.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The Naive Solution&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One possible solution would be to let &lt;code&gt;PaymentService&lt;/code&gt; understand every gateway directly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
    |
    +-- LegacyBankClient
    |
    +-- ModernPayClient
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, this creates strong coupling. Every new gateway would require modifications to the same class. In addition, conversion logic would also end up inside it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
    +-- convert PaymentRequest to LegacyBank format
    +-- convert LegacyBank response
    +-- convert PaymentRequest to ModernPay format
    +-- convert ModernPay response
    +-- execute payment business rules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Different responsibilities are clearly being mixed together.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Architecture Using Adapter&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The proposed solution creates an internal contract called:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;PaymentGateway&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every payment provider used by the application will be exposed through this interface.&lt;/p&gt;

&lt;p&gt;The architecture becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customer
   |
   v
Checkout API
   |
   v
PaymentService
   |
   v
PaymentGateway
   |
   +----------------+
   |                |
   v                v
LegacyBankAdapter  ModernPayAdapter
   |                |
   v                v
LegacyBank API     ModernPay API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The most important point is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;PaymentService&lt;/code&gt; does not know the external providers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It only knows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;PaymentGateway&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;Visual Representation 1 — UML Class Diagram&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The first diagram required by the assignment represents the structure of the classes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsai41klkvqwqq901033u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsai41klkvqwqq901033u.png" alt=" " width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this diagram, we can clearly identify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Target -&amp;gt; PaymentGateway

Client -&amp;gt; PaymentService

Adapters -&amp;gt; LegacyBankAdapter and ModernPayAdapter

Adaptees -&amp;gt; LegacyBankClient and ModernPayClient
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The UML diagram should not be merely decorative.&lt;/p&gt;

&lt;p&gt;It must accurately reflect the code presented in the article.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Visual Representation 2 — Software Architecture&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now we can view the pattern within a broader software ecosystem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F86ecftec8ewejws51xn0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F86ecftec8ewejws51xn0.png" alt=" " width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The two diagrams serve different purposes.The UML diagram explains:&lt;/p&gt;

&lt;p&gt;• How are the classes organized?&lt;/p&gt;

&lt;p&gt;The architecture diagram explains:&lt;/p&gt;

&lt;p&gt;• Where does the Adapter fit within the overall system?&lt;/p&gt;

&lt;p&gt;That distinction is important because they represent two different perspectives.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Java Implementation&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now let's implement exactly what was shown in the UML diagram.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;1. Creating the Internal Contract&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, we define the interface representing any payment gateway accepted by our application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nc"&gt;PaymentResult&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PaymentRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This interface has a simple responsibility:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;receive a payment request and return its result.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Notice that we are not using any LegacyBank or ModernPay-specific types.&lt;/p&gt;

&lt;p&gt;This is intentional.&lt;/p&gt;

&lt;p&gt;Our domain should not depend on external provider models.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;&lt;strong&gt;2. Defining the Payment Request&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We can use a &lt;code&gt;record&lt;/code&gt;, available in modern versions of Java.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.math.BigDecimal&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="nf"&gt;PaymentRequest&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;orderId&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;BigDecimal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;customerId&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using &lt;code&gt;BigDecimal&lt;/code&gt; for monetary values is preferable to floating-point types such as &lt;code&gt;double&lt;/code&gt; inside the application's domain.&lt;/p&gt;

&lt;p&gt;Our system keeps its preferred internal model.&lt;/p&gt;

&lt;p&gt;If a specific external API requires a &lt;code&gt;double&lt;/code&gt;, the Adapter is responsible for performing that conversion.&lt;/p&gt;

&lt;p&gt;This detail matters.&lt;/p&gt;

&lt;p&gt;The domain should not be weakened simply because an external integration uses a particular representation.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;&lt;strong&gt;3. Standardizing the Result&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We also create our own response type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="nf"&gt;PaymentResult&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;approved&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;transactionId&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Regardless of which provider is used, the rest of the application always receives a &lt;code&gt;PaymentResult&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This standardizes how responses are consumed.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;&lt;strong&gt;4. The Legacy Client&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Imagine that we have no control over this class.&lt;/p&gt;

&lt;p&gt;It could come from a third-party library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;LegacyBankClient&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;LegacyBankResponse&lt;/span&gt; &lt;span class="nf"&gt;executeCharge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;reference&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="s"&gt;"Processing payment through LegacyBank..."&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;LegacyBankResponse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="s"&gt;"OK"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="s"&gt;"LEGACY-"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its response also belongs to the external provider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="nf"&gt;LegacyBankResponse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;transactionCode&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem is clear.&lt;/p&gt;

&lt;p&gt;Our internal contract provides:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;pay&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PaymentRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;LegacyBank provides:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;executeCharge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;reference&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interfaces are incompatible.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;&lt;strong&gt;5. Creating LegacyBankAdapter&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now we create the bridge between both contracts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;LegacyBankAdapter&lt;/span&gt;
        &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;LegacyBankClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;LegacyBankAdapter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;LegacyBankClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;PaymentResult&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;PaymentRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;LegacyBankResponse&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;executeCharge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;orderId&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
                        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;doubleValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;approved&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="s"&gt;"OK"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;equalsIgnoreCase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                        &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;approved&lt;/span&gt;
                &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s"&gt;"Payment approved"&lt;/span&gt;
                &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Payment declined"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PaymentResult&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;approved&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;transactionCode&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
                &lt;span class="n"&gt;message&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the core of the pattern.&lt;/p&gt;

&lt;p&gt;Notice the two conversions.&lt;/p&gt;

&lt;p&gt;First:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;orderId&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;doubleValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;convert our internal object into the parameters expected by LegacyBank.&lt;/p&gt;

&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;transactionCode&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;are converted into:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;PaymentResult&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a result, the rest of the system never needs to know that LegacyBank uses &lt;code&gt;"OK"&lt;/code&gt; as a status value.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;&lt;strong&gt;6. Implementing ModernPay&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now consider another provider.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.math.BigDecimal&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ModernPayClient&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;ModernPayResponse&lt;/span&gt; &lt;span class="nf"&gt;createPayment&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;customerId&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;BigDecimal&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;orderId&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="s"&gt;"Processing payment through ModernPay..."&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ModernPayResponse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="s"&gt;"MODERN-"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="nf"&gt;ModernPayResponse&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;successful&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;paymentId&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The incompatibility still exists.&lt;/p&gt;

&lt;p&gt;But now we do not need to modify &lt;code&gt;PaymentService&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We simply create another Adapter.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;&lt;strong&gt;7. ModernPayAdapter&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ModernPayAdapter&lt;/span&gt;
        &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;ModernPayClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;ModernPayAdapter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;ModernPayClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;PaymentResult&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;PaymentRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;ModernPayResponse&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createPayment&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;customerId&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
                        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
                        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;orderId&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;successful&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                        &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s"&gt;"Payment approved"&lt;/span&gt;
                        &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Payment declined"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PaymentResult&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;successful&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
                &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;paymentId&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
                &lt;span class="n"&gt;message&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, provider-specific details remain isolated.&lt;/p&gt;

&lt;p&gt;ModernPay works with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;successful
paymentId
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our system works with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;approved
transactionId
message
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Who translates between them?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ModernPayAdapter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;&lt;em&gt;8. Identifying the Providers&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We create an enum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;enum&lt;/span&gt; &lt;span class="nc"&gt;PaymentProvider&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="no"&gt;LEGACY_BANK&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="no"&gt;MODERN_PAY&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This avoids directly working with Strings such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="s"&gt;"LEGACY"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="s"&gt;"MODERN"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and reduces the chance of typing errors.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;9. Creating PaymentService&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we can write the main payment service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.Map&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentService&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;
            &lt;span class="nc"&gt;PaymentProvider&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt;
            &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;gateways&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;PaymentService&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PaymentProvider&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;gateways&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;gateways&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;gateways&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;PaymentResult&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;PaymentProvider&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;PaymentRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt; &lt;span class="n"&gt;gateway&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="n"&gt;gateways&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gateway&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;IllegalArgumentException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                    &lt;span class="s"&gt;"Gateway not configured: "&lt;/span&gt;
                            &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt;
            &lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;gateway&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;pay&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code demonstrates an important architectural change.&lt;/p&gt;

&lt;p&gt;The service does not contain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;LegacyBankClient&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;ModernPayClient&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It contains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;PaymentGateway&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means that &lt;code&gt;PaymentService&lt;/code&gt; depends on an abstraction.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;10. Configuring the Application&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we create the objects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.math.BigDecimal&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.Map&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt; &lt;span class="n"&gt;legacyGateway&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;LegacyBankAdapter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;LegacyBankClient&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt; &lt;span class="n"&gt;modernGateway&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ModernPayAdapter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ModernPayClient&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PaymentProvider&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="n"&gt;gateways&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;

                &lt;span class="nc"&gt;PaymentProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;LEGACY_BANK&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;legacyGateway&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;

                &lt;span class="nc"&gt;PaymentProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;MODERN_PAY&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;modernGateway&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;PaymentService&lt;/span&gt; &lt;span class="n"&gt;paymentService&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PaymentService&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gateways&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;PaymentRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PaymentRequest&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                        &lt;span class="s"&gt;"ORDER-1001"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;BigDecimal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"299.90"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
                        &lt;span class="s"&gt;"CUSTOMER-500"&lt;/span&gt;
                &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;PaymentResult&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="n"&gt;paymentService&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;process&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                        &lt;span class="nc"&gt;PaymentProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;MODERN_PAY&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                        &lt;span class="n"&gt;request&lt;/span&gt;
                &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="s"&gt;"Payment approved: "&lt;/span&gt;
                        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;approved&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="s"&gt;"Transaction: "&lt;/span&gt;
                        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;transactionId&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="s"&gt;"Message: "&lt;/span&gt;
                        &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;What Happens During Execution?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Suppose we select:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;PaymentProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;MODERN_PAY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The execution flow will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Main
 |
 v
PaymentService.process()
 |
 v
Map looks up MODERN_PAY
 |
 v
ModernPayAdapter
 |
 v
ModernPayClient
 |
 v
ModernPay API
 |
 v
ModernPayResponse
 |
 v
ModernPayAdapter converts it
 |
 v
PaymentResult
 |
 v
PaymentService
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we select:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;PaymentProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;LEGACY_BANK&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the flow only changes after the provider selection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
 |
 v
LegacyBankAdapter
 |
 v
LegacyBankClient
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The core business logic remains unchanged.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Adding a Third Gateway&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine that the company decides to integrate another provider:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FastPay
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without Adapter, we might need to modify &lt;code&gt;PaymentService&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;With the current architecture, we can simply create:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FastPayAdapter&lt;/span&gt;
        &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;FastPayClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;FastPayAdapter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;FastPayClient&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;PaymentResult&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;PaymentRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;// Conversion for FastPay&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PaymentResult&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="s"&gt;"FAST-123"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="s"&gt;"Payment approved"&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="no"&gt;FAST_PAY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to the enum and configure the implementation.&lt;/p&gt;

&lt;p&gt;The internal logic of &lt;code&gt;PaymentService&lt;/code&gt; remains almost unchanged.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Relationship With SOLID Principles&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Although Adapter is a Design Pattern and SOLID is a separate set of principles, there is an interesting relationship between them.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Dependency Inversion Principle&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One of the biggest improvements in this architecture can be seen here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
      |
      v
PaymentGateway
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
      |
      v
ModernPayClient
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
      |
      v
LegacyBankClient
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The business layer now depends on an abstraction.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Single Responsibility Principle&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
    +-- payment business logic
    +-- LegacyBank conversion
    +-- ModernPay conversion
    +-- external API handling
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
    +-- coordinates payment processing

LegacyBankAdapter
    +-- handles LegacyBank integration

ModernPayAdapter
    +-- handles ModernPay integration
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Responsibilities are more clearly separated.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Open/Closed Principle&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ideally, we want the system to remain open for extension while avoiding unnecessary modifications to existing code.&lt;/p&gt;

&lt;p&gt;Adding another gateway mainly means creating another implementation of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;PaymentGateway&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;instead of inserting more provider-specific details into the core payment logic.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Testability&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Another important benefit is the ability to test &lt;code&gt;PaymentService&lt;/code&gt; without calling real payment gateways.&lt;/p&gt;

&lt;p&gt;We can create a fake gateway:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FakePaymentGateway&lt;/span&gt;
        &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;PaymentResult&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="nc"&gt;PaymentRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PaymentResult&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="s"&gt;"TEST-123"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="s"&gt;"Test payment approved"&lt;/span&gt;
        &lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.math.BigDecimal&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.Map&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentServiceTest&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

        &lt;span class="nc"&gt;PaymentGateway&lt;/span&gt; &lt;span class="n"&gt;fakeGateway&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;FakePaymentGateway&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="nc"&gt;PaymentService&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PaymentService&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                        &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                                &lt;span class="nc"&gt;PaymentProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;MODERN_PAY&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                                &lt;span class="n"&gt;fakeGateway&lt;/span&gt;
                        &lt;span class="o"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;PaymentResult&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;process&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                        &lt;span class="nc"&gt;PaymentProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;MODERN_PAY&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;PaymentRequest&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                                &lt;span class="s"&gt;"ORDER-1"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;BigDecimal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"100.00"&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
                                &lt;span class="s"&gt;"CUSTOMER-1"&lt;/span&gt;
                        &lt;span class="o"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;approved&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means our test does not depend on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;internet access;&lt;/li&gt;
&lt;li&gt;real APIs;&lt;/li&gt;
&lt;li&gt;credentials;&lt;/li&gt;
&lt;li&gt;gateway availability;&lt;/li&gt;
&lt;li&gt;actual financial transactions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The abstraction makes automated testing significantly easier.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Before and After&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We can summarize the architectural change.&lt;/p&gt;

&lt;p&gt;◘ Before&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
    |
    +-- LegacyBankClient
    |
    +-- ModernPayClient
    |
    +-- LegacyBank conversion
    |
    +-- ModernPay conversion
    |
    +-- provider-specific integration rules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;◘ After&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
      |
      v
PaymentGateway
      |
      +-- LegacyBankAdapter
      |       |
      |       v
      |   LegacyBankClient
      |
      +-- ModernPayAdapter
              |
              v
          ModernPayClient
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The total number of classes may increase. However, the responsibilities become clearer and better organized.That leads to an important point.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Design Patterns Do Not Necessarily Reduce the Amount of Code&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There is a common misconception that applying a Design Pattern will always result in less code.&lt;/p&gt;

&lt;p&gt;That is not necessarily true.&lt;/p&gt;

&lt;p&gt;In this example, we could place everything in a single class using a few &lt;code&gt;if&lt;/code&gt; statements.&lt;/p&gt;

&lt;p&gt;We would probably have fewer files.&lt;/p&gt;

&lt;p&gt;But code size is not the only relevant metric.&lt;/p&gt;

&lt;p&gt;We also need to consider:&lt;/p&gt;

&lt;p&gt;• maintainability;&lt;br&gt;
• readability;&lt;br&gt;
• evolution;&lt;br&gt;
• testability;&lt;br&gt;
• coupling;&lt;br&gt;
• impact of changes;&lt;br&gt;
• separation of responsibilities.&lt;/p&gt;

&lt;p&gt;In small projects, creating several adapters may be unnecessary.In systems with multiple integrations and constant evolution, this separation becomes much more valuable.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Advantages of the Adapter Pattern&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;1. Reduced Coupling&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The main business logic no longer depends directly on external APIs. This prevents third-party details from spreading throughout the system.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;2. Change Isolation&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Imagine that ModernPay changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;paymentId
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;transactionReference
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Most of the impact can remain restricted to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ModernPayAdapter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The domain does not necessarily need to change.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;&lt;strong&gt;3. Legacy System Integration&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We do not always have the ability to modify older systems. An Adapter allows us to use a legacy system without changing its original implementation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;4. Easier Provider Replacement&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If LegacyBank is no longer used, its Adapter can be removed without rewriting the entire payment flow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;5. Better Testability&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Real implementations can be replaced with fakes, mocks, or stubs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;6. Domain Protection&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;External models do not need to spread across the rest of the application.&lt;/p&gt;

&lt;p&gt;Instead of using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;ModernPayResponse&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;throughout the system, we immediately convert it into:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;PaymentResult&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Disadvantages and Trade-Offs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every Design Pattern has a cost.&lt;/p&gt;

&lt;p&gt;Using Adapter also introduces additional complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;1. More Classes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For each integration, we may end up with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client
Adapter
DTOs
Mapper
Configuration
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a small project, this may feel excessive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;2. More Levels of Indirection&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;◘ Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
 |
 v
API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;◘ After:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
 |
 v
PaymentGateway
 |
 v
Adapter
 |
 v
Client
 |
 v
API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The architecture becomes more flexible, but also introduces more layers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;3. Adapters Still Require Maintenance&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Adapter does not eliminate external changes.&lt;/p&gt;

&lt;p&gt;If ModernPay changes its API, we still need to update code.&lt;/p&gt;

&lt;p&gt;The difference is that we try to contain that change within the Adapter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;4. Overly Generic Interfaces Can Become Problematic&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine that LegacyBank supports:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;refunds
installments
Pix
bank slips
credit cards
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;while ModernPay supports only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;credit cards
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creating one huge interface that attempts to represent every feature from every provider may create another architectural problem.&lt;/p&gt;

&lt;p&gt;The abstraction must represent meaningful concepts within the domain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;5. Adapter Does Not Solve Availability Problems&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is important not to assign responsibilities to the pattern that it does not have.&lt;/p&gt;

&lt;p&gt;Adapter does not automatically solve:&lt;/p&gt;

&lt;p&gt;• timeouts;&lt;br&gt;
• service outages;&lt;br&gt;
• circuit breaking;&lt;br&gt;
• retries;&lt;br&gt;
• load balancing;&lt;br&gt;
• high availability;&lt;br&gt;
• network failures;&lt;br&gt;
• duplicate requests;&lt;br&gt;
• idempotency.&lt;/p&gt;

&lt;p&gt;These concerns require additional architectural mechanisms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adapter Is Not Strategy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Adapter and Strategy can appear together, but they solve different problems.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Adapter&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How can components with different interfaces work together?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentGateway
       |
       v
ModernPayAdapter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;Strategy&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How can I select between different algorithms or behaviors?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentStrategy
   +-- CheapestGatewayStrategy
   +-- FastestGatewayStrategy
   +-- FallbackGatewayStrategy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A more advanced architecture could use both.&lt;/p&gt;

&lt;p&gt;Strategy could decide:&lt;/p&gt;

&lt;p&gt;• Which gateway should be used?&lt;/p&gt;

&lt;p&gt;Adapter would handle:&lt;/p&gt;

&lt;p&gt;• How do we communicate with the selected gateway?&lt;/p&gt;

&lt;p&gt;This distinction matters because Design Patterns are not necessarily competitors.&lt;/p&gt;

&lt;p&gt;They can be combined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adapter Is Not Facade Either&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Facade has a different purpose.Its goal is to provide a simplified interface to a complex subsystem.&lt;/p&gt;

&lt;p&gt;Adapter has another primary concern:&lt;/p&gt;

&lt;p&gt;• compatibility between interfaces.&lt;/p&gt;

&lt;p&gt;An Adapter may simplify an integration as a side effect, but its main intention is to adapt incompatible contracts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When Should You Use Adapter?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Adapter is particularly useful when:&lt;/p&gt;

&lt;p&gt;• an external library does not match the application's expected contract;&lt;br&gt;
• multiple external APIs need to be integrated;&lt;br&gt;
• legacy systems need to be incorporated;&lt;br&gt;
• the domain should be protected from third-party models;&lt;br&gt;
• different providers perform similar functions through different interfaces;&lt;br&gt;
• an existing class cannot be modified directly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When Might Adapter Be Unnecessary?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Design Patterns should not be applied simply because they exist.&lt;/p&gt;

&lt;p&gt;Adapter may be overengineering when:&lt;/p&gt;

&lt;p&gt;• there is only one extremely simple integration;&lt;br&gt;
• the external interface already matches the application's needs;&lt;br&gt;
• there is no realistic expectation of evolution;&lt;br&gt;
• the extra layer does not provide meaningful maintainability benefits.&lt;/p&gt;

&lt;p&gt;The context should justify the abstraction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Broader Architectural View&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In a real-world application, Adapter would only be one part of the overall architecture.&lt;/p&gt;

&lt;p&gt;We could have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    +---------------+
                    |   Front-end   |
                    +-------+-------+
                            |
                            v
                    +---------------+
                    | Checkout API  |
                    +-------+-------+
                            |
                            v
                    +---------------+
                    | Order Service |
                    +-------+-------+
                            |
                            v
                    +---------------+
                    |PaymentService |
                    +-------+-------+
                            |
                            v
                    +---------------+
                    |PaymentGateway |
                    +-------+-------+
                            |
               +------------+-------------+
               |                          |
               v                          v
      +-----------------+       +-----------------+
      |LegacyBankAdapter|       |ModernPayAdapter |
      +--------+--------+       +--------+--------+
               |                          |
               v                          v
      +-----------------+       +-----------------+
      | LegacyBank API  |       | ModernPay API   |
      +-----------------+       +-----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Around these integrations, we could also add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Retry
Timeout
Circuit Breaker
Logging
Metrics
Tracing
Authentication
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This demonstrates an important architectural lesson:&lt;/p&gt;

&lt;p&gt;The Adapter solves a specific problem.&lt;/p&gt;

&lt;p&gt;It is not the entire architecture.&lt;/p&gt;

&lt;p&gt;It is one component within it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this article, we analyzed the &lt;strong&gt;Adapter Pattern&lt;/strong&gt; in a scenario involving a Java application integrating multiple payment gateways.&lt;/p&gt;

&lt;p&gt;The original problem was not simply that two APIs were different.&lt;/p&gt;

&lt;p&gt;The real issue was the coupling that could emerge if the business layer started depending directly on each provider's specific contract.&lt;/p&gt;

&lt;p&gt;The solution was to introduce an abstraction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;PaymentGateway&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and create adapters responsible for translating each external API into that common contract.&lt;/p&gt;

&lt;p&gt;We moved from an architecture like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
   |
   v
Specific providers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PaymentService
   |
   v
PaymentGateway
   |
   v
Adapters
   |
   v
External APIs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The main benefit of the pattern is not reducing the number of lines of code.&lt;/p&gt;

&lt;p&gt;Its real value is &lt;strong&gt;controlling dependencies&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;By isolating external integrations, we can improve important system characteristics such as:&lt;/p&gt;

&lt;p&gt;• maintainability;&lt;br&gt;
• testability;&lt;br&gt;
• readability;&lt;br&gt;
• extensibility;&lt;br&gt;
• change isolation;&lt;br&gt;
• separation of responsibilities.&lt;/p&gt;

&lt;p&gt;At the same time, there is a cost.&lt;/p&gt;

&lt;p&gt;We introduce more classes, more interfaces, and more levels of indirection.&lt;/p&gt;

&lt;p&gt;For that reason, just like any other Design Pattern, Adapter should not be applied automatically.&lt;/p&gt;

&lt;p&gt;It should be used when the architectural problem genuinely justifies it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My Perspective on the Pattern&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After studying Adapter in more depth, I realized that the implementation itself is not particularly complex. Creating a class that implements an interface and delegates calls to another class is relatively straightforward. The most interesting part is the architectural decsion behind it.&lt;/p&gt;

&lt;p&gt;The real value appears when we understand that we are creating a boundary between:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;our system
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;an external system
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That boundary prevents external implementation details from spreading throughout the application.It also made it clearer to me that Design Patterns are not mandatory recipes.The most important step is identifying the problem first. Only then should we evaluate whether a particular pattern is the right solution.&lt;/p&gt;

&lt;p&gt;In this payment gateway scenario, Adapter makes sense because we have different providers performing essentially the same business function while exposing incompatible contracts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;• Gamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John.&lt;br&gt;
Design Patterns: Elements of Reusable Object-Oriented Software.&lt;br&gt;
Addison-Wesley, 1994.&lt;/p&gt;

&lt;p&gt;• Freeman, Eric; Robson, Elisabeth.&lt;br&gt;
Head First Design Patterns.&lt;br&gt;
O'Reilly Media.&lt;/p&gt;

&lt;p&gt;• Oracle Java Documentation.&lt;/p&gt;

&lt;p&gt;• Refactoring.Guru — Adapter Design Pattern.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What About You?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you were building a platform that needed to integrate five or six different payment gateways, how would you structure those integrations? Would you use the Adapter Pattern to create a common interface, or would you choose a different approach?&lt;/p&gt;

</description>
      <category>java</category>
      <category>designpatterns</category>
      <category>architecture</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
