基类继承的VB语法



我想知道以下代码片段的含义。特别是部分:"实体类型为{BusinessEntity,New}("。我对VB继承有点陌生,所以有些语法对我来说有点陌生。我知道基类被用来为从它继承的所有业务对象添加功能,但语法让我有点反感。这种设计模式有名字吗?

Public Class AppObjectBase(Of EntityType As {BusinessEntity, New})
    Inherits BusinessObject(Of EntityType)
...
...
Public Class NavTreeObj
    Inherits NavTree(Of NavTreeEntity)
End Class
Public Class NavTree(Of EntityType As {NavTreeEntity, New})
    Inherits AppObjectBase(Of EntityType)
    ...
    ...

您知道Of EntityType部分本身的含义吗?如果没有,那么您应该阅读有关泛型类型的内容。至于As {BusinessEntity, New}部分,这意味着EntityType必须是或继承自BusinessEntity类型,并且它还必须具有无参数构造函数。通过在泛型类型参数上指定这些约束,您可以访问BusinessEntity类型的成员,还可以调用构造函数在方法中创建新实例。

最新更新