Use the generic List(Of T)
class, specialized to hold your Client
objects. It already provides all of the methods you want without your having to write a single line of code!
So you would first write a Client
class that contained all of the properties (data) and methods (actions) relating to a "client":
Public Class Client
Public Property Name As String
Public Property AmountOwned As Decimal
Public Sub Bill()
BillingManager.BillClient(Me)
End Sub
' ... etc.
End Class
Then, you would create the List(Of T)
to hold all of your instances of the Client
class:
Dim clients As New System.Collections.Generic.List(Of Client)
If, for whatever reason, you needed to specialize the behavior of the Add
, Remove
, etc. methods provided by the collection class, or add additional methods, you would need to change strategies slightly. Instead of using List(Of T)
, you would inherit from Collection(Of T)
and create a custom collection class like so:
Public Class ClientCollection
Inherits System.Collections.ObjectModel.Collection(Of T)
' ... customize as desired ...
End Class
The WinForms ListBox
class doesn't do it exactly like this because it was written before generics were introduced to the framework. But since they're here now, and you should always use them when possible, you can completely ignore how WinForms does things.