The adaptor pattern is the first design pattern from the structural patterns that we're going to discuss
about generally.
This pattern is used when there is a need to combine the capabilities of the interfaces.
You can think of this pattern as a plug adaptor linking two components that are not compatible with
each other, just like a power socket that does not accept a certain plug and needs an adapter to address
that.
You can use this pattern whenever you are in one of the following situations, you have a legacy application
or interface and you wish to make it work with a newer application, you can use the adapter pattern
to connect the two together without having to change the legacy component.
Another use case is when you need to convert an interface into another.
This is a way to adapt to incompatible interfaces together.
Also, an important use case is when you want to adopt some requests of a client application to a new
Web service and adoptive parent can provide a link to ensure compatibility between the two.
The adoptive father is being used thoroughly in the Java API as well.
Some examples are the collections framework where you can change a collection to another.
One example is changing a race to lists using the athlete's method.
Also, the extremes have plenty of adaptors to make those dreams work with other types of streams or
readers.
Here is a design diagram of a Dr. Peter.
In our example, we will be using a legacy banking application, which needs to send information structure
in a very specific way.
The information will be sent to a news service which, based on the information, will create a banking
account.
We will be using an interface for creating the account and getting the information needed for that account
and then the doctor class that will implement that interface, which will structure the information
based on the contract with the service, the requests will go from the adapter to the service and eventually
the account will be created.
Let's see how this looks in code.