© Dmitri Nesteruk 2019
Dmitri NesterukDesign Patterns in .NEThttps://doi.org/10.1007/978-1-4842-4366-4_7

7. Adapter

Dmitri Nesteruk1 
(1)
St. Petersburg, c.St-Peterburg, Russia
 

I used to travel quite a lot, and a travel adapter that lets me plug a European plug into a UK or U.S. socket1 is a very good analogy for 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 are working with a library that’s great at drawing pixels. You, on the other hand, work with geometric objects—lines, rectangles, and that sort of thing. You want to keep working with those objects, but also need the ...

Get Design Patterns in .NET: Reusable Approaches in C# and F# for Object-Oriented Software 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.