Search code examples
c#comcom-interop

Why is there interface / class (IFoo, FooClass) pattern in Office Interop API?


In the Microsoft.Office.Interop.Visio library each entity (for e.g Shape), is described as a class (ShapeClass) and an interface, Shape.

So for each element you have:

interface Shape { ... }
class ShapeClass : Shape { ... }

interface Page { ... }
class PageClass : Page { ... }

...

Why is it designed like this?


Solution

  • The "Interop" part of the namespace hints that this is actually a COM-based API.

    COM was Microsoft's first attempt at a language-neutral component model for developers, and one of its core tenets was interface-based design.

    So, in your example, ShapeClass is called a "co-class", which is a named implementation of the Shape interface.

    Co-classes were registered globally (in the Win32 registry) and could be created based on their friendly name ("prog-ID") or a GUID, called "CLSID".