我有2个接口,IAccount和IEmailAccount。 IEmailAccount包含与IAccount相同的所有属性和方法,以及一些与电子邮件相关的扩展。有没有办法用Interfaces做类似继承的类?我试图从IEmailAccount中删除2之间共享的所有常见属性/方法,但如果我有一个IAccounts列表,我希望能够在该列表中包含IEmailAccounts ...
Public Interface IAccount
Property Username As String
Property Password As String
Property LoginCookie As Net.CookieContainer
Property CreationDate As Date
Property LastLoginDate As Date
Property EmailAccount As IEmailAccount
Property Proxy As HelperLib.Proxy
Sub Login()
Sub Create()
End Interface
Public Interface IEmailAccount
Property Username As String
Property Password As String
Property LoginCookie As Net.CookieContainer
Property CreationDate As Date
Property LastLoginDate As Date
Property EmailAccount As IEmailAccount
Property Proxy As HelperLib.Proxy
Property Emails As List(Of Email)
Sub Login()
Sub Create()
Sub SendMail(recipient As String, title As String, body As String)
Function GetEmails() As List(Of Email)
End Interface
Public MustInherit Class EmailAccountBase
Implements IEmailAccount
Implements IAccount
Public Property Emails As List(Of Email) Implements IEmailAccount.Emails
Public Property Username As String Implements IEmailAccount.Username, IAccount.Username
Public Property Password As String Implements IEmailAccount.Password, IAccount.Password
Public Property LoginCookie As CookieContainer Implements IEmailAccount.LoginCookie, IAccount.LoginCookie
Public Property CreationDate As Date Implements IEmailAccount.CreationDate, IAccount.CreationDate
Public Property LastLoginDate As Date Implements IEmailAccount.LastLoginDate, IAccount.LastLoginDate
Public Property EmailAccount As IEmailAccount Implements IEmailAccount.EmailAccount, IAccount.EmailAccount
Public Property Proxy As Proxy Implements IEmailAccount.Proxy, IAccount.Proxy
Public MustOverride Sub Login() Implements IEmailAccount.Login, IAccount.Login
Public MustOverride Sub Create() Implements IEmailAccount.Create, IAccount.Create
Public MustOverride Sub SendMail(recipient As String, title As String, body As String) Implements IEmailAccount.SendMail
Public MustOverride Function GetEmails() As List(Of Email) Implements IEmailAccount.GetEmails
Public Sub New(username As String, password As String)
Me.Username = username
Me.Password = password
End Sub
End Class
答案 0 :(得分:1)
是的,很简单:
Public Interface IAccount
Property Username As String
Property Password As String
Property LoginCookie As Net.CookieContainer
Property CreationDate As Date
Property LastLoginDate As Date
Property EmailAccount As IEmailAccount
Property Proxy As HelperLib.Proxy
Sub Login()
Sub Create()
End Interface
Public Interface IEmailAccount
Inherits IAccount
Property Emails As List(Of Email)
Sub SendMail(recipient As String, title As String, body As String)
Function GetEmails() As List(Of Email)
End Interface