Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Sub Main()
  2. Dim ac As New AppleCart({New Apple(), New Apple()})
  3. For Each a In ac.Fruits
  4. a.Rot() ' prints "The apple is rotten!"
  5. Next
  6. Console.Read()
  7. End Sub
  8.  
  9. Public Class Fruit
  10. Public Overridable Sub Rot()
  11. Console.WriteLine("The fruit is rotten!")
  12. End Sub
  13. End Class
  14.  
  15. Public Class Apple
  16. Inherits Fruit
  17. Public Overrides Sub Rot()
  18. Console.WriteLine("The apple is rotten!")
  19. End Sub
  20. End Class
  21.  
  22. Public Class FruitStand(Of T As Fruit)
  23. Private _fruits As List(Of T)
  24. Public ReadOnly Property Fruits As IEnumerable(Of T)
  25. Get
  26. Return _fruits
  27. End Get
  28. End Property
  29. Public Sub New(fruits As IEnumerable(Of T))
  30. _fruits = fruits.ToList()
  31. End Sub
  32. End Class
  33.  
  34. Public Class AppleCart
  35. Inherits FruitStand(Of Apple)
  36. Public Sub New(fruits As IEnumerable(Of Apple))
  37. MyBase.New(fruits)
  38. End Sub
  39. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement