Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Once you "get" interfaces, OOP really falls into place. To put it simply, an interface defines a set of public method signatures, you create a class which implements those methods. This allows you generalize functions for any class which implements a particular interface (i.e. classes which have the same methods), even if those classes don't necessarily descend from one another.</p> <pre><code>Module Module1 Interface ILifeform ReadOnly Property Name() As String Sub Speak() Sub Eat() End Interface Class Dog Implements ILifeform Public ReadOnly Property Name() As String Implements ILifeform.Name Get Return "Doggy!" End Get End Property Public Sub Speak() Implements ILifeform.Speak Console.WriteLine("Woof!") End Sub Public Sub Eat() Implements ILifeform.Eat Console.WriteLine("Yum, doggy biscuits!") End Sub End Class Class Ninja Implements ILifeform Public ReadOnly Property Name() As String Implements ILifeform.Name Get Return "Ninja!!" End Get End Property Public Sub Speak() Implements ILifeform.Speak Console.WriteLine("Ninjas are silent, deadly killers") End Sub Public Sub Eat() Implements ILifeform.Eat Console.WriteLine("Ninjas don't eat, they wail on guitars and kick ass") End Sub End Class Class Monkey Implements ILifeform Public ReadOnly Property Name() As String Implements ILifeform.Name Get Return "Monkey!!!" End Get End Property Public Sub Speak() Implements ILifeform.Speak Console.WriteLine("Ook ook") End Sub Public Sub Eat() Implements ILifeform.Eat Console.WriteLine("Bananas!") End Sub End Class Sub Main() Dim lifeforms As ILifeform() = New ILifeform() {New Dog(), New Ninja(), New Monkey()} For Each x As ILifeform In lifeforms HandleLifeform(x) Next Console.ReadKey(True) End Sub Sub HandleLifeform(ByVal x As ILifeform) Console.WriteLine("Handling lifeform '{0}'", x.Name) x.Speak() x.Eat() Console.WriteLine() End Sub End Module </code></pre> <p>None of the classes above descend from one another, but my HandleLifeform method is generalized to operate on all of them -- or really any class which implements the ILifeform interface.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload