使用Me对象


MustInherit Class Person
Overridable Function TableName() As String
Return "Person"
End Function
Sub Save
DoSomething(Me)
End Sub
End Class
Class Staff
Inherits Person
Overrides Function TableName() As String
Return "Staff"
End Function
Overloads Sub Save()
MyBase.Save()
DoSomething(Me)
End Sub
End Class
Sub DoSomething(o as Object)
DoAnotherThing(o.TableName)
End Sub

有没有办法让我在DoSomething中引用Person in Person ?在Staff.Save?目前它们都引用Staff实例。

我试图写一个通用的例程保存属性到数据库,(继承-不是我的代码)的问题是有3个对象继承人(员工,客户端,联系人)和吨几乎重复的代码,这使得4数据库表(人有数据共同的3)。

我想知道这个结构是否有帮助

MustInherit Class BasePersons
'stuff common to classes that Inherit here
MustOverride Function TableName() As String
MustOverride Sub Save()
Sub DoSomething(BP As BasePersons)
'code
Debug.WriteLine(BP.TableName)
End Sub
End Class
Class Person
Inherits BasePersons
Overrides Function TableName() As String
Return "Person"
End Function
Overrides Sub Save()
DoSomething(Me)
End Sub
End Class
Class Staff
Inherits BasePersons
Overrides Function TableName() As String
Return "Staff"
End Function
Overrides Sub Save()
DoSomething(Me)
End Sub
End Class

因为它只适用于一个对象,所以我只是重新定义了几个子元素

Sub DoSomething(o as Object, optional IsPerson as Boolean = false)
Dim TableName As String = If(IsPerson, "Person", obj.TableName)        
DoAnotherThing(o, TableName)
End Sub
Sub DoAnotherThing(o as Object, TableName as string)

出租汽车司机,不是面向对象的,但这对我来说足够好了。

相关内容

  • 没有找到相关文章

最新更新