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?
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.
The term 'shim' is used to describe an adapter, facade or proxy in Structural patterns.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With