Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the exact difference between 'Adapter' and 'Mediator" patterns?

I know that Adapter is a structural pattern and Mediator is a behavioral one. But as far I understood, what both of them are doing, is connecting two (or more) other classes which are potentially incompatible (not so maintainable) for direct communication.

Can some one give a close comparison between these two and point out the exact difference?

These are the links for Adapter and Mediator explanations in TutorialsPoint.

And these are sourcemaking explanations. Adapter, Mediator.

like image 588
Supun Wijerathne Avatar asked Jun 12 '16 12:06

Supun Wijerathne


1 Answers

JB Nizet already wrote a good answer. I just want to explain the differences in simpler words:

  • Mediator should be used when you don't know how to communicate with other objects or you aren't allowed to

  • Adapter should be used when you know exactly how to communicate with objects, but these objects might not support some communication methods or differ

like image 110
Dzianis Yafimau Avatar answered Sep 20 '22 09:09

Dzianis Yafimau