用来表示继承层次结构中两个类型之间的距离的术语



我有一个扩展方法来计算基类型和派生类型之间的距离,这样相同的类型将返回值0,而直接子类型将返回值1。描述这个标量最简洁和常用的术语是什么?

更具体地说,我该如何命名下面的方法才能有意义并有效地传达意图?

    public static int? CalculateHowDeeplyDerivedTheDescendantTypeIsFromTheBaseType(this Type baseType, Type descendantType)
    {
        baseType = baseType ?? typeof(System.Object);
        descendantType = descendantType ?? typeof(System.Object);
        if (!baseType.IsAssignableFrom(descendantType))
            return descendantType.IsAssignableFrom(baseType)
                       ? -1*CalculateHowDeeplyDerivedTheDescendantTypeIsFromTheBaseType(descendantType, baseType)
                       : null;
        if (baseType == descendantType)
            return 0;
        return CalculateHowDeeplyDerivedTheDescendantTypeIsFromTheBaseType(baseType, descendantType.BaseType) + 1;
    }

我想你要找的术语是Depth of Inheritance

继承深度,也称为继承树深度(Depth of inheritance tree, DIT),定义为"从节点到树的根的最大长度"

壁虎比尔可能说对了。然而,作为与图论相关的通用选项,您可以将其称为LengthOfPathToDerivedClass。

链路、连接或路径的长度。指与链接、连接或路径相关联的标签。这个标签可以是距离、流量、容量或该链路的任何属性。路径的长度是指该路径上的链路(或连接)的数量。

最新更新