What's the definition of a Shim?
相关问题
- Operator precedence in C Definitions
- Selector for “Define” Edit Menu item in iOS 5
- Order of Class Definitions in C++
- What do we call the combined path, query, and frag
- “Scraping” vs. “Scrapping”: Is there a difference?
相关文章
- What does “exposition only” mean? Why use it?
- “Adapter” or “adaptor”?
- What is {{$guid}} used for in Postman?
- What is a bit field in layman's terms?
- In which way is akka real-time?
- CSS pseudo-class vs. pseudo-selector
- What does “CL” mean in a commit message? What does
- Does the implementation of pow() function in C/C++
From Wikipedia:
The General Concept - 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. This is the general concept. Please refer to the answers above for something more technical.
As for origins of the word, quoth Apple's Dictionary widget
This seems to fit quite well with how web designers use the term.
The term "shim" as defined in Wikipedia would technically be classified, based on its definition, as a "Structural" design pattern. The many types of “Structural” design patterns are quite clearly described in the (some would say defacto) object oriented software design patterns reference "Design Patterns, Elements of Reusable Object-Oriented Software" better known as the "Gang of Four".
The "Gang of Four" text outlines at least 3 well established patterns known as, "Proxy", "Adapter" and "Facade" which all provide “shim” type functionality. In most fields it’s often times the use and or miss use of different acronyms for the same root concept that causes people confusion. Using the word “shim” to describe the more specific “Structural” design patterns "Proxy", "Adapter" and "Facade" certainly is a clear example of this type of situation. A "shim" is simply a more general term for the more specific types of "Structural" patterns "Proxy", "Adapter", "Facade" and possibly others.
Shims are used in .net 4.5 Microsoft Fakes framework to isolate your application from other assemblies for unit testing. Shims divert calls to specific methods to code that you write as part of your test
According to Microsoft's article "Demystifying Shims":
I interpret this to mean that a shim is a generic term for any library of code that acts as a middleman and partially or completely changes the behavior or operation of a program. Like a true middleman, it can affect the data passed to that program, or affect the data returned from that program.
The article uses the Windows API as an example, and I found the following sentence relevant:
To generalize this quote, the two programs that make the "bread" of the "shim sandwich" should not be able to differentiate between talking to their counterpart program and talking to the shim.
What are some pros and cons of using shims?
Again, from the article:
In the context of this question, terms like "proxy", "adapter", and "facade" make more sense (at least to me) after having read the above link.