简体   繁体   English

VB.Net是否有一种接口可以从另一个接口继承的方法?

[英]VB.Net Is there a way to for an interface to inherit from another interface?

I have 2 interfaces, IAccount and IEmailAccount. 我有2个接口,即IAccount和IEmailAccount。 IEmailAccount contains all of the same properties and methods as IAccount, plus a few extensions related to email. IEmailAccount包含与IAccount相同的所有属性和方法,以及与电子邮件相关的一些扩展。 Is there a way to do something similar to class inheritance with Interfaces? 有没有一种方法可以执行类似于与Interfaces进行类继承的操作? I tried removing all of the common properties/methods shared between the 2 from IEmailAccount, but if I have a List of IAccounts, I want to be able to include IEmailAccounts in that list... 我尝试从IEmailAccount中删除两者之间共享的所有通用属性/方法,但是如果我有一个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

Yes, it's simple: 是的,很简单:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM