What is the difference between the Facade and Adapter Pattern?

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

    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.

    0 讨论(0)
  • 2021-01-30 00:18

    The difference between these two patterns is clear, but not in the realm of Design Patterns, but Domain Modeling. In the following, I'll explain why.

    First, I want to reiterate others have said here, and then I'll add the note:

    A Facade is an interface to a subsystem (an external or a legacy system) that simplifies the access for the client (us). Facade hides the interface of the other subsystem (aggregate some calls, or hide some APIs that we don't need), thus your client only accesses that subsystem through this Facade.

    On the other hand, an Adapter is a wrapper around another service or object. It makes the wrapped object conform to a standard interface that the client expects. Let's say there is a method on the "Ledger" object, which you need to make a tweak (change its parameters, change its name, etc.). You can wrap it with an adapter.

    Now, still the difference might not be clear. That's where I want to bring up the key difference between these two patterns leaving no room for further confusion:

    Facade doesn't changes the domain model of the other subsystem, while Adapter does. This is the key difference. Period.

    That's why you combine these two when you create an Anticorruption Layer. Let's say you have subsystem which you want to use, but you don't want its domain model to muddle your domain model. What would you do? You'd create an Anticorruption Layer. How? You first create a Facade, that simplifies accessing the interface for the subsystem, and then adapters for the domain objects used in that interface (remember the facade still holds the domain model for the other subsystem), so it conforms to your model.

    Many design patterns can be used in domain modeling. This is true for Facade and Adapter design patterns, as well. Although the difference between these two patterns might not be clear in "design pattern" realm, it's more clear in "domain modeling" realm.

    0 讨论(0)
  • 2021-01-30 00:22

    Adapter == making a square peg fit into a round hole.

    Facade == a single control panel to run all the internal components.

    0 讨论(0)
  • 2021-01-30 00:27

    A facade is designed to organize multiple services behind a single service gateway. An adapter is designed to provide a way to use a known interface to access an unknown one.

    0 讨论(0)
  • 2021-01-30 00:27

    The purpose of a

    facade is simplicity

    adapter is interoperability.

    0 讨论(0)
  • 2021-01-30 00:27

    Adapter pattern links two incompatible interfaces by providing a new interface.

    Facade pattern simplifies a complex subsystem(having multiple components) with a single interface.

    0 讨论(0)
提交回复
热议问题