Implement an Interface : Interface « Class « VB.Net






Implement an Interface

Implement an Interface
Imports System
Imports System.Collections


Public Class MainClass

  Shared Sub Main()

    Dim e1 As New Programmer("E1", 50000)
    Dim e2 As New Employee("E2", 40000)
    
    Dim theTeam As Employee() = {e1, e2}
    
    e1.MyTeam = theTeam
    
    Console.WriteLine(e1.Rate(e2))
    
  End Sub
End Class


Public Interface ILead
  Sub SpendMoraleFund(ByVal amount As Decimal)
  Function Rate(ByVal aPerson As Employee) As String
  Property MyTeam() As Employee()
  Property MoraleFund() As Decimal
End Interface

Public Class Programmer
  Inherits Employee
  Implements ILead
  Private m_MoraleFund As Decimal
  Private m_MyTeam As Employee()
  Public Function Rate(ByVal aPerson As Employee) As String _
  Implements ILead.Rate
    Return aPerson.TheName & " rating to be done"
  End Function
  Public Property MyTeam() As Employee() _
  Implements ILead.MyTeam
    Get
      Return m_MyTeam
    End Get
    Set(ByVal Value As Employee())
      m_MyTeam = Value
    End Set
  End Property
  Public Sub SpendMoraleFund(ByVal amount As Decimal) _
  Implements ILead.SpendMoraleFund
    'spend some money
    Console.WriteLine("Spent " & amount.ToString())
  End Sub
  Public Property OurMoraleFund() As Decimal Implements ILead.MoraleFund
    Get
      Return m_MoraleFund
    End Get
    Set(ByVal Value As Decimal)
      m_MoraleFund = Value
    End Set
  End Property
  Public Sub New(ByVal theName As String, ByVal curSalary As Decimal)
    MyBase.New(theName, curSalary)
  End Sub
End Class

Public Class Employee
  Private m_Name As String
  Private m_Salary As Decimal

  Public Sub New(ByVal theName As String, ByVal curSalary As Decimal)
    m_Name = theName
    m_Salary = curSalary
  End Sub

  Public ReadOnly Property TheName() As String
    Get
      Return m_Name
    End Get
  End Property

  Public ReadOnly Property Salary() As Decimal
    Get
      Return MyClass.m_Salary
    End Get
  End Property

End Class


           
       








Related examples in the same category

1.One Class implements two Interfaces which have the same name methodOne Class implements two Interfaces which have the same name method
2.Interface inherits interfaceInterface inherits interface
3.Class implements two interfaces
4.Implements an InterfaceImplements an Interface
5.Define and use Interface AgeDefine and use Interface Age
6.Interface Inherits another InterfaceInterface Inherits another Interface
7.Define and use InterfaceDefine and use Interface
8.Implements Two InterfacesImplements Two Interfaces
9.Generic Class and InterfaceGeneric Class and Interface