Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created November 6, 2012 13:22
Show Gist options
  • Save dtinth/4024721 to your computer and use it in GitHub Desktop.
Save dtinth/4024721 to your computer and use it in GitHub Desktop.
An Adapter Analogy

An Adapter Analogy

Suppose that you have a very old keyboard, which uses a PS/2 port. It is a really good keyboard for gaming but unfortunately, it isn't being manufactured anymore, and you love it very much.

Now also suppose that your favorite PC has died, and you bought a new laptop just to notice that it does not have a PS/2 port anymore. Instead, your laptop has several USB ports.

What would you do if you really want to use the keyboard with your computer?


You wouldn't modify your laptop and add a PS/2 port to it. After all, it is a new, shiny laptop and maybe you don't feel like modifying it yet.

You also wouldn't modify your old keyboard and change it into USB. Remember that you love the keyboard very much, and you might break it by modifying the keyboard.

So what would you do then? You would buy an adapter that lets you use your PS/2 keyboard with your USB port. You don't have to modify the laptop or keyboard. You just use an adapter and your PC sees your PS/2 keyboard like any other USB keyboard.

This is analogous to the adapter pattern in OOP.


Let's go back and talk about the adapter: is the adapter itself the keyboard?

Actually it's an adapter which adapts the keyboard plugged on to it, but the computer sees it as a keyboard.

Does the computer need to know (or should it care) that it's actually an adapter and not a keyboard? Probably not...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment