What is the difference between the Facade and Adapter Pattern?

后端 未结 16 935
孤城傲影
孤城傲影 2021-01-29 23:50

I\'ve been reading both definitions and they seem quite the same. Could anyone point out what are their differences?

Thanks

16条回答
  •  无人共我
    2021-01-30 00:36

    Facade:

    Key takeaways : ( from journaldev article by Pankaj Kumar)

    1. Facade pattern is more like a helper for client applications
    2. Facade pattern can be applied at any point of development, usually when the number of interfaces grow and system gets complex.
    3. Subsystem interfaces are not aware of Facade and they shouldn’t have any reference of the Facade interface
    4. 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:

    1. It is a structural pattern
    2. It is useful to work with two incompatible interfaces
    3. It makes things work after they're designed

    Class diagram of Adapter:

    You can find more details about Adapter in this SE post:

    Difference between Bridge pattern and Adapter pattern

    Key differences:

    1. 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
    2. 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.

提交回复
热议问题