user1520312
user1520312

Reputation: 167

Is an Adapter and Converter the same thing?

What's the difference between an Adapter and a Converter? Are all converters Adapters?

(In terms of design patterns)

Upvotes: 14

Views: 6292

Answers (1)

Peter Ritchie
Peter Ritchie

Reputation: 35870

No, I wouldn't consider them the same thing. An adapter is something that generally adapts one interface for another. For example, I might create an adapter interface for my application to send an email. One adapter would do all the work involved in interfacing with SMTP, another adapter might do all the work involved in interfacing with Exchange. The the code using either of the adapters, they would be used in the same way (maybe both implementing the same interface). The adapters adapt one interface for another. The idea is that I could swap them out as needed.

A converter is something that changes one or more values to one or more different values. e.g. I may need to convert Unicode text into ASCII text. That's not adapting an interface so that something else that expects a different interface can use it, that's converting values so that the single interface that expected ASCII text can be used.

Now, an adapter might need to do some conversion in order to adapt an interface; but that's not always the case.

Upvotes: 24

Related Questions