Simple Explanation via Cartoon
An example of a shim:
Summary
A shim is some code that takes care of what’s asked (by ‘interception’), without anyone being any wiser about it.
Example of a Shim
An example of a shim would be rbenv (a neat ruby tool). Calls to ruby commands are “shimmed”. i.e. when you run bundle install
, rbenv intercepts that message, and reroutes it according to the specific version of Ruby you are running. If that doesn’t make sense try this example, or just think of the fairy god mother intercepting messages and delivering apposite outcomes.
That’s it!
Important Clarifications on this example
- Note: Like most analogies, this is not perfect: usually Ralph will get EXACTLY what he asked for – but the mechanics of HOW it was obtained is something Ralph doesn’t care about. If Ralph asks for dog food, a good shim will deliver dog food.
- Also, I didn’t want to get into semantic arguments (nor needless details/complexity – e.g. Adapter gang of four design pattern etc. code samples etc.) so I deliberately simplified to a general concept via cartoon so you can quickly/easily get the gist – there are cons with such an approach – if you prefer encyclopedic definitions then consider the Wikipedia entry on shims.
PS: RIP Ralph. A more loyal pet never existed.