【问题标题】:OOP Nomenclature: what's the name for the full type name in Curiously Recurring Template Pattern?OOP 命名法:Curiously Recurring Template Pattern 中的完整类型名称是什么?
【发布时间】:2023-04-07 13:29:01
【问题描述】:

Curiously Recurring Template Pattern 是 Jim Coplien 的泛型基类名称,其实际泛型参数是派生类:

class Base<T> { ... }
class Derived: public Base<Derived> { ... } 

或者在 Java 中,例如 Comparable 和 Enums:

class Foo implements Comparable<Foo> { ... }
//or
enum Bar { ... } //  which is actually Bar extends Enum<Bar>

现在,这些类的类型名称依次为DerivedFooBar

但是我们把同样指定派生的东西叫做什么,即'Derived is-a Base'、'Foo implements Comparable'、'Bar extends Enum'。这不是类型名称,而是更多。

但是那个 typename-plus-derivation-name 的 word 是什么?

【问题讨论】:

    标签: java c++ oop


    【解决方案1】:

    这是有界多态性。 F-bound 是约束:

    interface I<A extends I<A>>
    //            ^----------^
    

    它在子类型中显示为

    class C extends I<C>
    

    【讨论】:

      【解决方案2】:

      在 Java 中,它在 language spec 中给出:

      给定一个(可能是通用的)类声明C&lt;F1,...,Fn&gt;(n ≥ 0, C ≠ Object),类类型C&lt;F1,...,Fn&gt;直接超类C声明的extends子句中给出的类型如果存在 extends 子句,否则 Object

      给定一个(可能是通用的)类声明C&lt;F1,...,Fn&gt;(n ≥ 0, C ≠ Object),类类型C&lt;F1,...,Fn&gt;直接超接口C声明的implements子句中给出的类型, 如果存在 implements 子句。

      所以,它只是被称为直接超类或直接超接口。它“奇怪地反复出现”这一事实没有特殊的名称。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-01-01
        • 2015-09-18
        • 2013-06-04
        • 1970-01-01
        • 2014-02-07
        • 2011-03-24
        • 1970-01-01
        相关资源
        最近更新 更多