Field Notes: The Adapter Pattern
Often, I will be in a situation similar to the one above, but the object being adapted does not do all the things I need.
In this case, I can still use the Adapter pattern, but it is not such a perfect fit. In this case,
Those functions that are implemented in the existing class can be adapted.
Those functions that are not present can be implemented in the wrapping object.
This does not give me quite the same benefit, but at least I do not have to implement all of the required functionality.
The Adapter pattern frees me from worrying about the interfaces of existing classes when I am doing a design. If I have a class that does what I need, at least conceptually, then I know that I can always use the Adapter pattern ...
Get Design Patterns Explained: A New Perspective on Object-Oriented Design now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.