Adapter

You need to recharge your mobile phone to call your family.
The problem is you come from France and you are still in Japan on business.

What are the options to solve this problem ?
  1. Modify your phone charger to be able to connect it to the japan socket.
  2. Buy another phone charger.
  3. Buy a simple adapter.

Solution 1:
  • The problem is your charger won't work when you'll return in France.
  • If you modify your charger you may break it.
  • You have to know exactly how your mobile charger works.
Solution 2:
  • It would be expensive
  • Maybe there is no charger available in Japan for your mobile.
  • You'll have two chargers to do the same thing = to recharge.
Solution 3:
  • It seems to be the less expensive solution.
  • You'll be able to recharge your phone when you'll return in France.
  • You'll be able to use the same trick in other countries.

THIS IS THE ADAPTER DESIGN PATTERN !!!

When you will be in the same situation =
You must keep your old objects but use new or external API.

Don't modify your objects, just make adapters !!!

Your adapter will implement/extend the expected interface/class.
Your adapter will contain an instance of the class it wraps.
Your adapter will make calls to the instance of the wrapped object.