分布式接口实现

时间:2015-08-24 13:51:35

标签: vb.net interface class-hierarchy

有没有办法在类层次结构上传播接口实现?请考虑以下示例。

Public Interface I
    Property X As String
    Property Y As String
    Property Z As String
End Interface

Public Class A
    Property X As String
    Property Y As String
End Class

Public Class B
    Inherits A
    Implements I

    Property Z As String
End Class

我想避免在X中重复YB。想想十个而不是两个。 而且我不想拆分接口I,因为B的继承应该是实现细节。

1 个答案:

答案 0 :(得分:0)

这可能对您的情况不起作用,但您可以使用Partial Classes。

这意味着你将失去A级: - (

您使用的是MVC Razor HTML帮助程序类吗?当界面没有在单个班级中实施时,我不认为他们喜欢它。

Public Interface I
    Property X As String
    Property Y As String
    Property Z As String
End Interface


Partial Public Class B
    Property X As String Implements I.X
    Property Y As String Implements I.Y
End Class

Public Class B

    Implements I

    Property Z As String Implements I.Z
End Class

不知道怎么解决这个问题...

编辑:

Public Interface iA
    Property X As String
    Property Y As String
End Interface

Public Interface iB
    Property Z As String
End Interface

Public Interface IAB
    Inherits iA
    Inherits iB
End Interface

Public Class A
    Implements iA
    Property X As String Implements iA.X
    Property Y As String Implements iA.Y
End Class

Public Class B
    Inherits A
    Implements IAB
    Property Z As String Implements iB.Z
End Class