Key takeaways : ( from journaldev article by Pankaj Kumar)
Facade pattern is more like a helper for client applications
Facade pattern can be applied at any point of development, usually when the number of interfaces grow and system gets complex.
Subsystem interfaces are not aware of Facade and they shouldn’t have any reference of the Facade interface
Facade pattern should be applied for similar kind of interfaces, its purpose is to provide a single interface rather than multiple interfaces that does the similar kind of jobs
Facade class diagram:
Adapter:
It is a structural pattern
It is useful to work with two incompatible interfaces
It makes things work after they're designed
Class diagram of Adapter:
You can find more details about Adapter in this SE post:
Facade defines a new interface, whereas Adapter uses an old interface. Adapter makes two existing interfaces work together as opposed to defining an entirely new one
Adapter and Facade are both wrappers; but they are different kinds of wrappers. The intent of Facade is to produce a simpler interface, and the intent of Adapter is to design to an existing interface
Have a look at sourcemaking article too for better understanding.
Adapter pattern allows two,previously incompatible, interfaces to work with each other. Has 2 separate interfaces in play.
The Facade pattern takes a known interface, that is low level/fine grained, and wraps it with a higher level/course grained interface. Has a single interface, that has been simplified by wrapping with another.
Facade exposes a single class to a higher, and more limited level. For example, a view model facade may only expose certain read only properties of a lower level class.
The Facade Pattern wiki page has a brief note about this.
"An Adapter is used when the wrapper
must respect a particular interface
and must support a polymorphic
behavior. On the other hand, a facade
is used when one wants an easier or
simpler interface to work with."
I heard an analogy that you should think of your universal remote control that you've set up to work with all your different stereo systems - you press "on" and it turns on your cable box, your receiver, and your TV. Maybe it's a really fancy home theater and it dims the lights and draws the shades too. That's a Facade - one button/function that takes care of a more complicated set of steps.
The Adapter pattern just links two incompatible interfaces.
EDIT: A quick analogy for the Adapter pattern (based on the comments) might be something like a DVI-to-VGA adapter. Modern video cards are often DVI, but you've got an old VGA monitor. With an adapter that plugs into your video card's expected DVI input, and has its own VGA input, you'll be able to get your old monitor working with your new video card.
Facade:
Key takeaways : ( from journaldev article by Pankaj Kumar)
Facade class diagram:
Adapter:
Class diagram of Adapter:
You can find more details about Adapter in this SE post:
Difference between Bridge pattern and Adapter pattern
Key differences:
Have a look at sourcemaking article too for better understanding.
Adapter pattern allows two,previously incompatible, interfaces to work with each other. Has 2 separate interfaces in play.
The Facade pattern takes a known interface, that is low level/fine grained, and wraps it with a higher level/course grained interface. Has a single interface, that has been simplified by wrapping with another.
Adapter makes two interfaces work together.
Facade exposes a single class to a higher, and more limited level. For example, a view model facade may only expose certain read only properties of a lower level class.
Having read all this, I have to say that the purpose of a
facade is simplicity
adapter is interoperability.
Adapter == making a square peg fit into a round hole.
Facade == a single control panel to run all the internal components.
The Facade Pattern wiki page has a brief note about this.
I heard an analogy that you should think of your universal remote control that you've set up to work with all your different stereo systems - you press "on" and it turns on your cable box, your receiver, and your TV. Maybe it's a really fancy home theater and it dims the lights and draws the shades too. That's a Facade - one button/function that takes care of a more complicated set of steps.
The Adapter pattern just links two incompatible interfaces.
EDIT: A quick analogy for the Adapter pattern (based on the comments) might be something like a DVI-to-VGA adapter. Modern video cards are often DVI, but you've got an old VGA monitor. With an adapter that plugs into your video card's expected DVI input, and has its own VGA input, you'll be able to get your old monitor working with your new video card.