Imports System
Imports System.Collections
Public Interface Printable
ReadOnly Property Print() As Integer
End Interface
Public Class Money
Implements Printable
Protected mTransactions As New ArrayList()
ReadOnly Property Print() As Integer Implements Printable.Print
Get
Return mTransactions.Count
End Get
End Property
Public Overridable ReadOnly Property Balance() As Double
Get
Dim result As Double = 0.0
Dim i As Integer
For i = 0 To mTransactions.Count - 1
result += CDbl(mTransactions(i))
Next
Return result
End Get
End Property
Public Sub Add(ByVal amount As Double)
mTransactions.Add(amount)
End Sub
Public Sub Subtract(ByVal amount As Double)
mTransactions.Add(-amount)
End Sub
End Class
Public Class MyMoney
Inherits Money
Public Overrides ReadOnly Property Balance() As Double
Get
Return MyBase.Balance - Print * 2
End Get
End Property
End Class
Module Test
Sub Main()
Dim acc1 As New Money()
acc1.Add(200)
acc1.Subtract(40)
acc1.Add(30)
Console.Write("count: {0}, ", acc1.Print)
Console.WriteLine("balance: {0}", acc1.Balance)
Dim acc2 As New MyMoney()
acc2.Add(200)
acc2.Subtract(40)
acc2.Add(30)
Console.Write("count: {0}, ", acc2.Print)
Console.WriteLine("balance: {0}", acc2.Balance)
End Sub
End Module
|