"Looking Up" the object hierarchy

  • Thread starter Thread starter tinman
  • Start date Start date
T

tinman

Hi....

Would appreciate some advice on how to achieve the following in an OOP
manner:

Supposed, I have the following object model:

Employee
|
| - - Projects
|
| - - Project

The Employee object has several properties, say, for example EmployeeID. How
is it
possible for any of the Project object to know what the associated
EmployeeID is?

I believe saving the Employee ID in each of the Project object (via some
property) is
a little overkill and not quite OOP.....right ? How else can this be
achieved ?

Thanks...
 
I believe saving the Employee ID in each of the Project object (via some
property) is
a little overkill and not quite OOP.....right ? How else can this be
achieved ?

Thanks...

It's a pretty common practice to give child objects some kind of a Parent
property. Just look at the windows forms Control class. It hosts
subcontrols via a ControlCollection. If you choose to go this route, you
would implement your own custom collection (call it ProjectCollection) and
in the Add and Remove methods, you'd put code that sets the Project's Parent
property.

Erik
 
Back
Top