Inheritance Collection Classes

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

I need to have a series of collection classes that inherit (I think) from
each other. What is the best way to do this in .NET? In VB6 I had a series
of collection classes each passing a reference to the parent object down the
tree.

For example:
Customer(s) -> Email(s) -> Attachment(s)

Or maybe:
Directory -> Directory -> Directory -> Files etc

Do I still simply pass teh reference to the parent down the tree?
I also need the child classes to get information form the parent.

You also can't put:

Public Class cAttachments
Inherits System.Collections.CollectionBase
Inherits cEmail
...
 
Hi Andrew,

class inheritance means that :
if you have a class A that inherit class B so the class A has all class B
caracteristics (Public and Protected attributes, procedures and functions).
it's like if you say that a baby got the eyes of his father and the mouth of
his mother;

Now what you want to do (if I understand) is to have a class Customer that
have an attribute Emails (which is a class or a collection of classes) wich
have a reference to the Customer class;
To do that, create your class Emails with a constructor which take the
Customer class in parameter and store it in an Emails class attribute :

Class Emails

Protected myCustomer as Customer

Public Sub new (Byref c As Customer)
myCustomer = c
End Sub

...

End Class



Regards
 
Thanks for the response. Your right my terminology is wrong.
I was rather hoping that there would be a better way of referencing the
parent class other than passing it to the child. This is the same as VB6.
Cheers.
 
Unfortunately this does not quite solve all my problems.

I need to get information for an item in a collection from one of it's
parents.

Ie, how would you suggest I get the customer email address (assuming this is
a property) form the email item.

I need something like :
Address = theEmail.Parent.CustomerEmail
 
Andrew said:
Unfortunately this does not quite solve all my problems.

I need to get information for an item in a collection from one of it's
parents.

Ie, how would you suggest I get the customer email address (assuming this is
a property) form the email item.

If your classes Email and Customer are defined like that :

Class Email

Public myCustomer as Customer

Public Sub new (Byref c As Customer)
myCustomer = c
End Sub

...

End Class

Class Customer

Protected myName as String
Public myEmails as ArrayList

Public sub new (byval n as String, byref emails as Arraylist)
myName = n
myEmails = emails
End Sub

Public readonly property getName () As String
Get
return myName
End Get
End property

...

End Class

I need something like :
Address = theEmail.Parent.CustomerEmail

Address = theEmail.myCustomer.myEmails



Regards
 
Back
Top