This entry is part of a series on programming Design Patterns that provides a framework for the rapid recall and use of patterns during application design.
The Adapter design pattern is used to wrap a class in code that allows that class to be used via a different interface. Another name for the pattern is a Wrapper.
To understand how this pattern might be used, consider how software to display an image on a fixed size device might be constructed. Assume the following class and method are provided by the standard device software:
class Display - contains methods to create displays on the device.
displayImage(source) - method that displays an image with the dimensions of the device screen.
An adapter would fit an image of any size to the device screen:
class DisplayAdapter - contains methods that fit an image of any size to the device screen.
imageAdapter(original) - method that changes the size of the original image to fit the display screen.
imageResample(original, resized) - method that resamples the image for size change.
displayImage(resized) - uses the method built into the device to display the resized image.