Exemples d'implémentation d'interface en Visual Basic
Mise à jour : novembre 2007
Les classes qui implémentent une interface doivent implémenter toutes ses propriétés, méthodes et événements.
L'exemple à suivre définit deux interfaces. La seconde interface, Interface2, hérite de Interface1 et définit une propriété et une méthode supplémentaires.
Interface Interface1
Sub sub1(ByVal i As Integer)
End Interface
' Demonstrates interface inheritance.
Interface Interface2
Inherits Interface1
Sub M1(ByVal y As Integer)
ReadOnly Property Num() As Integer
End Interface
L'exemple suivant implémente Interface1, l'interface définie dans l'exemple précédent :
Public Class ImplementationClass1
Implements Interface1
Sub Sub1(ByVal i As Integer) Implements Interface1.sub1
' Insert code here to implement this method.
End Sub
End Class
Ce dernier exemple implémente Interface2, y compris une méthode héritée de Interface1 :
Public Class ImplementationClass2
Implements Interface2
Dim INum As Integer = 0
Sub sub1(ByVal i As Integer) Implements Interface2.sub1
' Insert code here that implements this method.
End Sub
Sub M1(ByVal x As Integer) Implements Interface2.M1
' Insert code here to implement this method.
End Sub
ReadOnly Property Num() As Integer Implements _
Interface2.Num
Get
Num = INum
End Get
End Property
End Class
Voir aussi
Tâches
Comment : créer et implémenter des interfaces
Procédure pas à pas : création et implémentation d'interfaces
Concepts
Implements, mot clé et instruction