Learning the Adapter Pattern

The easiest way to understand the intent of the Adapter pattern is to look at an example of where it is useful. Let's say I have been given the following requirements:

  • Create classes for points, lines, and squares that have the behavior “display.”

  • The client objects should not have to know whether they actually have a point, a line, or a square. They just want to know that they have one of these shapes.

In other words, I want to encompass these specific shapes in a higher-level concept that I will call a “displayable shape.”

Now, as I work through this simple example, try to imagine other situations that you have run into that are similar, such as

  • You have wanted to use a subroutine or a method that someone else has ...

Get Design Patterns Explained: A New Perspective on Object-Oriented Design now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.