В чем разница между шаблонами прокладки и фасада / адаптера?

StackOverflow https://stackoverflow.com/questions/9512690

Вопрос

Я разрабатываю приложение, которое нужно работать с различными несовместимыми версиями какой-то библиотеки.Мой инстинкт кишечника ввел адаптер между приложением и библиотекой, который будет иметь надлежащий объект библиотеки, введенной в нее.Затем кто-то сказал мне о промах.Об этом не много литературы.

Я хотел узнать, как прокладываются от фасада и шаблона дизайна адаптера?И каковы некоторые из популярных применений того же?

Это было полезно?

Решение

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