Users can use interfaces in vb.net to complete the implementation of polymorphism. By using multiple interfaces, users can allow system components to run multiple software without disrupting the running of code.
interfaces describe properties and methods like classes, but unlike classes, interfaces do not provide any implementation.
in order to use interfaces for polymorphism, the user must first establish an interface and implement the interface through several other classes. In almost the same way, users can invoke methods that other objects have already implemented.
The following example is a method of using an interface to implement polymorphism:
Namespace polynamespace Interface Animal Sub Move (ByRef Distance as Double) Sub Bite (Byval What as OBJ ECT) End Interface Class Flea Implements Animal public Sub bite (Byval What as Object) Implements
Al.bite ' Bite something End Sub sub-move (ByRef Distance as Double) Implements Animal.move Distance=distance+1 End Sub-End Class class Dog Implements animal public Sub bite (Byval What As Object) Implements animal.bite ' bite something End Sub sub-move (ByRef Distance as Double) Implements Animal.move distance=distance+100 End Sub-end Class end Namespace ' Add this section to the Your form Pr otected Sub button1_click (Byval sender as System.object,_ Byval e as System.EventArgs) Dim Aflea as New F Lea () Dim anobj As Object () Dim adog As New Dog () Getfood (aflea,anobj) Getfood (adog,anobj) End Sub Public Sub Getfood (Byval Critter AS animal,byval Food as Object) Dim dbldistance as Double ' Code to calculate distance to Food (omitted). Critter.move (dbldistance) ' Early bound (vtable) critter.bite (Food) ' Early bound (vtable) End Sub