我正在开发一个需要使用不同不兼容的某些库的应用程序的应用程序。我的GUT Instinct正在在应用程序和库之间引入一个适配器,该库将具有注入其中的库的适当对象。然后,有人告诉我关于垫片。没有太多的文学。

我想知道如何与外立面和适配器设计模式不同的垫片?其中一些流行的用途是什么?

有帮助吗?

解决方案

In my eyes, an Adapter and a Shim would be the same.

A Facade on the other hand serves a different purpose. If you expect your client code to need to be able to pull back the curtain, so to speak, and access the underlying library without using your object model, that would be a Facade. Facade presents a simplified or common set of objects/methods on top of a more complex system, but still provides access to the underlying complexities when additional behavior is required.

The use of Adapter means your client code is completely, blissfully unaware of the underlying implementation details.

其他提示

IMO, Adapter and Shim functions similarly but means something different.

A Shim usually has very similar, if not exact, set of interface with the object being "shimmed." For example, proxy objects could be considered somewhat like a shim.

While an Adapter usually has quite different, if not completely different, set of interface with the object being "adapted."

Note the "shim" and "adapt" verb. That's how I usually differentiate the two.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top