Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 846
user1520312 Avatar asked Jul 21 '12 00:07

user1520312


1 Answers

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.

like image 131
Peter Ritchie Avatar answered Sep 19 '22 15:09

Peter Ritchie