Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why exposed types must be sealed for WinMD/WinRT components?

VS compiler does not allow to create sealed exposed types for WINMD type library.

Why is this restriction placed ? (I know about sealed types advantages, my question is with respect to Win RT components).

like image 531
Tilak Avatar asked May 08 '12 06:05

Tilak


1 Answers

This is an architectural limitation, imposed by COM. Which sits at the core of any WinRT type, they are derived from IUnknown and IInspectable. The problem with COM is that it only supports interface inheritance but not implementation inheritance. Which was a strong COM design goal, implementation inheritance is too fraught with implementation details, including the infamous diamond problem.

There is a way to make inheritance work by delegation, each method in the derived class explicitly calls the corresponding base interface method, but that's very painful to do yourself. But otherwise the way that Windows.UI.Xaml classes implement inheritance.

like image 73
Hans Passant Avatar answered Sep 28 '22 04:09

Hans Passant