The Adapter Pattern (sometimes called the wrapper pattern) allows objects satisfying one interface to be used where another type of interface is expected. There are two typical flavours of the pattern: the delegation flavour and the inheritance flavour.
h3 Delegation Example
Suppose we have the following classes:
We can ask the RoundHole class if a RoundPeg fits in it, but if we ask the same question for a SquarePeg, then it will fail because the SquarePeg class doesn't have a radius property.
To get around this problem, we can supply an adapter as follows:
We can use the adapter like this:
Which results in the following output: