We are now ready to move on to the structure of design patterns and the first pattern we're going to
take a look at is the adapter design pattern which is very simple.
It's all about getting the interface that you want from the interface that you were given by some system
or other.
So the typical representation of an adapter is just the same as you have in the power captor's.
So you know that electrical devices in the real world have different power requirements and you can
speak of these requirements as interface requirements.
So it's first of all the voltage that you get out of the system so in different countries there's different
voltage and you have to adapt for that and also the fact that you know portable devices might only use
5 volts whereas in the mains you have 220 volts or 120 in the United States for example.
In addition there is the actual interface so the socket or the plug type is different in Europe the
UK the USA or Australia I believe as well.
And so as a frequent traveler I used to travel as a technical evangelist.
I would run into this trouble of not having the right adapter.
So eventually you go ahead and you buy the adapter which kind of adapts everything to everything.
But we cannot really take the gadgets that we have with us and just modify them to support every possible
interface and indeed the manufacturers of electrical products do not give you an adapter for every country
out there.
So you have to buy that separately some support for different systems as possible.
So for example when you buy a shaver that shaver the adapter would probably support both 220 volts as
well as 120 in the United States but that's about it.
Thats the only device I can think of which actually goes out of its way to support different electrical
systems.
So we need a special device which is called an adapter to give us the interface that we require from
the interface that we have.
So we might have that see a 220 volt interface but we need an adapter so that it can give just 5 volts
to the mobile phone that we need for example.
So the adapter design pattern then is this same idea in software.
So it is a software construct and typically it can be a class or an interface or something like that.
So its a contract which adapts an existing interface acts to conform to the required interface.
So what this means is that you have let's say you are getting the interface X from some system but some
other system requires interface y.
So what you have to do is you have to sort of connect one to the other and you write an extra piece
of code to make that possible.