为什么必须对WinMD/WinRT组件的裸露类型进行密封? [英] Why exposed types must be sealed for WinMD/WinRT components?

查看:146
本文介绍了为什么必须对WinMD/WinRT组件的裸露类型进行密封?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS编译器不允许为WINMD类型库创建密封的公开类型.

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

为什么要设置此限制? (我知道密封类型的优点,我的问题是关于Win RT组件的.)

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

推荐答案

这是COM施加的体系结构限制.它们是任何WinRT类型的核心,它们是从IUnknown和IInspectable派生的. COM的问题在于它仅支持接口继承,但不支持实现继承.这是一个很强的COM设计目​​标,实现继承对实现细节(包括臭名昭著的菱形问题)充满了困惑.

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.

有一种方法可以通过委派来使继承起作用,派生类中的每个方法都显式调用相应的基本接口方法,但是自己做起来很痛苦.但是,否则Windows.UI.Xaml类实现继承的方式.

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.

这篇关于为什么必须对WinMD/WinRT组件的裸露类型进行密封?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆