Shim

Why Trust Techopedia

What Does Shim Mean?

Shim, in C#, is a template class that is derived from a base class with derived classes that inherit the data and behavior of the base class and vary only in the type. The derived class of the shim class reuses the implementation provided by the shim class.

Advertisements

Shim can be designed to act as a thin compatibility layer, which can resolve the compatibility issues that may arise during the development of newer versions of applications. It is also used to execute applications on software platforms for which they were not originally designed.

In general, the shim class is mainly used to provide access to functionality only through the derived classes of the shim class. This approach helps provide code extensibility. It also prevents code duplication and avoids errors due to cut-and-paste. This can mean lower costs and less maintenance.

Techopedia Explains Shim

A shim class is a template class that takes type as a parameter. It can be used at any level of an inheritance chain and can provide better maintenance and extension of the hierarchy.

A shim class can be implemented using containment and aggregation methods. In case of a containment approach, the shim class passes on its calls to the re-implementation of the interface to provide additional behavior. In the aggregation method, the interface to the inner class is passed to the outer object and there is no specialization of the behavior of the inner object.

For example, Wine is a shim that enables many Windows applications to execute on operating systems like Linux, Solaris, etc.

In cases where the call to unmanaged code needs to be forwarded from managed code after some initializations, shim class can be used as a wrapper class. This shim class can be created as a more generic class that cannot be used directly but allows for the generation of derived classes that have common functionality. It helps build a framework wherein the shim class forms the link between the base class that contains common functionalities and the derived classes that have customized functions.

A COM shim that links a Microsoft Office host application and managed extension helps provide security and isolates multiple Microsoft Office extensions.

Advertisements

Related Terms

Margaret Rouse
Technology Specialist
Margaret Rouse
Technology Specialist

Margaret is an award-winning writer and educator known for her ability to explain complex technical topics to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles in the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret’s idea of ​​a fun day is to help IT and business professionals to learn to speak each other’s highly specialized languages.