Lecture thumbnail 0:05 / 2:36 We are now ready to move on to the structural 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 adapters.

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 five volts, whereas in the mains

you have 220V 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, 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 can’t 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 is possible.

So, for example, when you buy a shaver, that shaver adapter would probably support both to 20V as

well as 120 in the United States.

But that’s about it.

That’s 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 a, let’s say a 220 volt interface, but we need an adapter so that it can give just

five 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 it’s a construct which adapts an existing interface 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.

Stop Play Play Play Play Start Play information alert