2

After visit dozens of pages searching a "non-sockets-or-iphone-conceptual-example" of Adapter Pattern, I have found this one:

enter image description here

enter image description here

Lloyds bank is an international bank offers services worldwide. For offshore account holders, the tax rate is 0.03%. And, in India it offers two types of accounts, Standard and Platinum. Tax rules are not applied to indian bank accounts. Now the offshore bank is incompatible to Indian account types. We need to design an AccountAdapter to make both the incompatible account types to work together.

So Can this example enough to accomplish the concepts of object adapter, adaptee and client?

1
  • Seems good. I would just name the adapter OffshoreAccountAdapter.
    – slepic
    Commented Feb 28, 2020 at 6:44

1 Answer 1

5

This follows the Object Adapter Pattern because the adapter uses the adaptee (rather than inherit from it as a Class Adapter would). One nit pick is it's missing the client from the class diagram.

In this case the adapter is effectively renaming getOffshoreBalance() to getBalance() and it's hiding a lot of unneeded other methods. I think it's a good example of the adapter pattern.

However, please please please stop using double for money

3
  • I agree; I just wanted to say - if the client is written against the Account interface (or against the AbstractAccount class), then the adaptee is really being adapted to conform to that interface (or class, respectively), rather then renaming a single method (conceptually, at least, even though this may be achieved through that single method). Commented Feb 28, 2020 at 9:06
  • Thanks! Just one more question? The "class" version of Adapter is only possible using multiple inheritance languages like python?
    – celsowm
    Commented Feb 28, 2020 at 11:29
  • @celsowm: No, it is also possible in languages where a class can inherit from one class and inherit/implement an unrelated interface at the same time, which includes most OO languages with single inheritance as well. In such a setup AccountAdapter would have to directly implement the Account interface, rather than inheriting from AbstractAccount, to be able to inherit from OffshoreAccount. Commented Feb 28, 2020 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.