Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the shim and facade/adapter patterns?

I'm developing an application that need to work with different incompatible versions of some library. My gut instinct was introducing an adapter between the app and the library that will have proper object of the library injected in it. Then, someone told me about shims. Not much literature is available about it.

I wanted to know how are shims different from facade and adapter design pattern? And what are some of the popular uses of the same?

like image 481
Anand Nalya Avatar asked Mar 01 '12 08:03

Anand Nalya


People also ask

What is difference between adapter and facade pattern?

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.

What is shim design pattern?

The term 'shim' is used to describe an adapter, facade or proxy in Structural patterns.

What is the difference between adapter and Bridge pattern?

Adapter pattern is used after the application components are designed so that we can use them without modifying the source code. This is in contrast to the Bridge pattern, which is used before the components are designed.

What are the two versions of adapter pattern?

If you do some research on the adapter pattern, you will find two different versions of it: The class adapter pattern that implements the adapter using inheritance. The object adapter pattern that uses composition to reference an instance of the wrapped class within the adapter.


Video Answer


1 Answers

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.

like image 140
tcarvin Avatar answered Sep 21 '22 18:09

tcarvin