Hei*_*nzi 4 .net language-agnostic oop
我有一个抽象的基类T,从中继承类A和B继承.我现在(的操作T),这需要一个稍微不同的实现A和B,但大部分的代码是一样的.让我举个例子:有两种.Clone方法可以实现类似方法:
Public MustInherit Class T
Protected MustInherit Function _DoClone() As T
Public Function Clone() As T
Dim clone = Me._DoClone() ' do the subclass-specific stuff '
... ' do the shared stuff '
End Function
End Class
Public Class A
Inherits T
Protected Overrides Function _DoClone() As T
... ' do the subclass-specific stuff '
End Function
End Class
Run Code Online (Sandbox Code Playgroud)
要么
Public MustInherit Class T
Protected Sub _DoClone(clone As T)
... ' do the shared stuff '
End Function
Public MustInherit Function Clone() As T
End Class
Public Class A
Inherits T
Public Overrides Function Clone() As T
Dim clone = ... ' do the subclass-specific stuff '
Me._DoClone(clone)
End Function
End Class
Run Code Online (Sandbox Code Playgroud)
(示例在VB.NET中,但同样的问题适用于C#,Java等)
我的问题:
_Do...事情),是否有完善的命名约定?