In the last lesson we looked at patterns in general and why we might want to use them. So here is our first pattern. We are well on our way to creating a common language with which to talk design.
One of the reasons I picked this pattern to start with, is that it is very easy to understand. It models real word situations very well, and that is what OO design is supposed to do right, model real world objects?
The Adapter in the Physical World
The concept of an Adapter is easy to understand. It does just what it is named to do. It adapts one object to that of another. Take the wall plug. It has three rectangular holes set at angles to fit the plug. It does? In Europe it does. We are traveling and need to plug our laptop into the wall. What do we use? An adapter.
The Adapter in the Software World
The idea is not so different in the software world. When you want to connect one class to another class that was not designed to fit together, you need an adapter class. Let’s look at an Java example to see how we can adapt one class to another.
Continue reading