View Single Post
Old 06-23-2005, 11:05 AM   #3 (permalink)
Mohan Giri
 
True Techie

Join Date: Dec 2004

Posts: 145

Mohan Giri

Default

Ok. Here is my code Mr.Iron_Cross.

Module advice
Public Class Wisdom
Delegate Function GiveAdvice() As String
Public Function Offeradvice(ByVal words As GiveAdvice) As String
Return (words())
End Function
End Class

Public Class Parent 'base type
Public Overridable Function Message() As String
Return ("You should listen to your elders")
End Function
End Class

Public Class Dad 'derived from the base parent type
Inherits Parent
Public Overrides Function Message() As String
Return ("You should listen to your mom")
End Function
End Class

Public Class Mom 'derived from the base parent type
Inherits Parent
Public Overrides Function Message() As String
Return ("You should listen to your Dad")
End Function
End Class

Public Class Daughter 'not derived from the base parent type
Public Function Message() As String
Return ("I know all there is to life")
End Function
End Class

Public Function CallAdvice(ByVal p As Parent) As String
Dim objParents As New Wisdom
Dim TeenAgeGirl As Wisdom.GiveAdvice = New Wisdom.GiveAdvice(AddressOf p.Message)
Return (objParents.Offeradvice(TeenAgeGirl))
End Function

Sub MainMenu()
Dim objDad As New Dad
Dim objmom As New Mom
Dim objDaughter As New Daughter
Console.WriteLine(CallAdvice(objDad))
Console.WriteLine(CallAdvice(objmom))

'will not work as this is not derived
'Console.WriteLine(CallAdvice(objDaughter))
End Sub
End Module
Mohan Giri is offline