O'Reilly logo

Design Patterns in Modern C++: Reusable Approaches for Object-Oriented Software Design by Dmitri Nesteruk

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© Dmitri Nesteruk 2018

Dmitri Nesteruk, Design Patterns in Modern C++, https://doi.org/10.1007/978-1-4842-3603-1_6

6. Adapter

Dmitri Nesteruk

(1)St. Petersburg, Russia

I used to travel quite a lot, and a travel adapter that lets me plug a European plug into a UK or USA socket1 is a very good analogy to what’s going on with the Adapter pattern: we are given an interface, but we want a different one, and building an adapter over the interface is what gets us to where we want to be.

Scenario

Here’s a trivial example: suppose you’re working with a library that’s great at drawing pixels. You, on the other hand, work with geometric objects—lines, rectangles, that sort of thing. You want to keep working with those objects but also need the rendering, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required