Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub Main()
- Dim ac As New AppleCart({New Apple(), New Apple()})
- For Each a In ac.Fruits
- a.Rot() ' prints "The apple is rotten!"
- Next
- Console.Read()
- End Sub
- Public Class Fruit
- Public Overridable Sub Rot()
- Console.WriteLine("The fruit is rotten!")
- End Sub
- End Class
- Public Class Apple
- Inherits Fruit
- Public Overrides Sub Rot()
- Console.WriteLine("The apple is rotten!")
- End Sub
- End Class
- Public Class FruitStand(Of T As Fruit)
- Private _fruits As List(Of T)
- Public ReadOnly Property Fruits As IEnumerable(Of T)
- Get
- Return _fruits
- End Get
- End Property
- Public Sub New(fruits As IEnumerable(Of T))
- _fruits = fruits.ToList()
- End Sub
- End Class
- Public Class AppleCart
- Inherits FruitStand(Of Apple)
- Public Sub New(fruits As IEnumerable(Of Apple))
- MyBase.New(fruits)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement