我想知道下面的代码片段是什么意思。特别是"Of EntityType As {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)
...
...发布于 2014-04-28 23:20:48
你知道Of EntityType部分本身意味着什么吗?如果不是,那么您应该阅读泛型类型。对于As {BusinessEntity, New}部分,这意味着EntityType必须是或继承于BusinessEntity类型,并且它还必须有一个无参数的构造函数。通过在泛型类型参数上指定这些约束,您可以访问BusinessEntity类型的成员,还可以调用构造函数在方法中创建新实例。
https://stackoverflow.com/questions/23352744
复制相似问题