I\'ve been reading both definitions and they seem quite the same. Could anyone point out what are their differences?
Thanks
I'll try to explain this in plain words, without much formality.
Imagine you've got some domain classes and from the UI you want to interact with them. A facade can be used to provide functions that can be called from the UI layer so that the UI layer doesn't know about any domain classes other than the facade. That means instead of calling the functions in the domain classes you call a single function from the facade, which will be responsible of calling the needed functions from the other classes.
An adapter, on the other hand, can be used to integrate other external components that might have the same functionality you need but their functions are not called quite the same way. Say you've got a Car
class in your domain and you work with an external car provider that has a Car class defined as well. In this class, you've got the function car.getDoors()
but the external provider has the equivalent car.getNumDoors()
. You don't want to change the way you call this function, so you can use an adapter class to wrap the external Car class so that a call to getDoors()
of the adapter is delegated to getNumDoors()
of the external class.