What is the difference between the Facade and Adapter Pattern?

后端 未结 16 1220
孤城傲影
孤城傲影 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:42

    Honestly, many patterns could be implemented the same way programmatically -- the difference is in intent.

    The Adapter design pattern is meant to 'translate' the interface of one or more classes into an interface that the client expects to use -- the adapter would translate the calls to the expected interface into the actual interface the wrapped classes use.

    The Facade pattern is used when a simpler interface is wanted (and again, could be implemented the same way by wrapping the offending classes.) You wouldn't say you're using a facade when the existing interface is incompatible, just when you need to make it more readable, less poorly-designed, etc.

提交回复
热议问题