2
Can we Say facade and Adapter are more or less in design patterns ?

Wikipedia explains this as :-

 Adapter Converts one interface to another so that it matches what the client is 
 expecting while Facade Provides a simplified interface. 

Looking at the UML representation in wiki http://en.wikipedia.org/wiki/Facade_pattern and adapter pattern http://en.wikipedia.org/wiki/Adapter_pattern I am not able to distinguish much between them . Can someone explain me the major point of difference in two ?

Invictus
  • 4,028
  • 10
  • 50
  • 80

3 Answers3

5

The Adapter design pattern "converts" a class interface into another that the client expect/can use. I.e. it facilitates the "cooperation" with incompatible interfaces.
I.e. adapts the existing interface of a class into one that the client can use.

The Facade design pattern offers a uniform interface for a set of interfaces of a system. It makes easier for the calling code to manipulate the system over a facade (The word facade comes from the French language, literally meaning "frontage" or "face";A facade or façade is generally one exterior side of a building, usually, but not always, the front. An outward appearance that is maintained to conceal a less pleasant or creditable reality).

Cratylus
  • 52,998
  • 69
  • 209
  • 339
  • So, would it be appropriate to speak of having an abstract class / interface that unifies access to certain functionality across various providers as a `facade`, while referring to a concrete implementation of that facade for a particular service as an `adapter`? – Faust Oct 19 '12 at 09:43
  • @Faust:No. These are 2 different patterns addressing different domains.One is not the implementation part of the other – Cratylus Oct 20 '12 at 09:03
2

The Adapter is specifically for when you need to adapt a class to a specific interface.

The Facade is about hiding messy interface(s) behind a simple one that does what you need it to.

Garrett Hall
  • 29,524
  • 10
  • 61
  • 76
  • But the the only differ being implementation of a specific interface and more than 1 interface in case of facade the major one ? As far as hiding mess is concerned , i guess adapter can also do the same – Invictus Sep 05 '12 at 16:30
1

A Facade could be an Adapter and vice versa but they generally have a different intents. A Facade is often used in an API to lower the barrier for using more simple functionality. Whereas an Adapter helps bridge the gap between two incompatible interfaces that need to communicate. An Adapter also enables decoupling of two systems so they each only need to depend on the Adapter interface.

Yoztastic
  • 862
  • 2
  • 8
  • 21