在VBA中通过接口模拟实现类继承的实例
Sub test() Dim mCustomer As New CCustomer Dim mSender As New CPerson With mCustomer .CustomerNumber = Me.txtNumber .Company = Me.txtCompany .Name = Me.txtName End With With mSender .Company = "北风试验室" .Name = "海陆空" End With ' 采用同一接口的约定 SendFollow mCustomer SendFollow mSender End Sub
Function SendFollow(obj As CPerson) As Boolean SendFollow = obj.SendFollowUp Debug.Print "Obj: " & TypeName(obj) End Function
注:CCustomer继承于CPerson