In a purchase, you have to collect many different types of addresses: billing, shipping and credit. Rather than have a separate class for each address, create a single class to hold address information and include an address type. You then can create a collection of the Address objects and assign it to a customer. Here is an example:
Public Enum OrderAddressType
Billing
Credit
Shipping
End Enum
Public Class OrderAddress
Public orderAddressType As OrderAddressType
Public strFirstName As String
Public strMI As String
Public strLastName As String
Public strStreet1 As String
Public strStreet2 As String
Public strCity As String
Public strStateProv As String
Public strPostalCode As String
Public strCountry As String
End Class
Public Class OrderAddressCollection
Inherits System.Collections.CollectionBase
Public Sub Add(ByVal oa As OrderAddress)
List.Add(oa)
End Sub
Public Sub Remove(ByVal index As Integer)
If index > Count - 1 Or index < 0 Then
'ignore request
Else
List.RemoveAt(index)
End If
End Sub
Default Public ReadOnly Property Item(ByVal index As Integer) As OrderAddress
Get
Return CType(list.Item(index), OrderAddress)
End Get
End Property
End Class
In the code above, CollectionBase was used as the base of the collection. In a simple Collection you only have the ability to identify the items in the collection by their location. If you need to identify the items in the collection by something other than the numeric index, then you have to use a DictionaryBase.
In my next post, I will give an examples of using DictionaryBase which I am working on now.