D
Dave Veeneman
I have an object hierarchy that's several layers deep, and I'm puzzling over
how to access an object at any point in the hierarchy, solely by its key.
The hierarchy is similar to an organizational chart, with a CEO at the top,
his/her subordinates in the next layer, their subordinates in the layer
below that, and so on. Each person is represented by an Employee object, and
Each Employee object has a Subordinates collection property (a dictionary),
which contains references to the Employee objects that represent their
subordinates, keyed by EmployeeID. So, the Employee objects are distributed
among a number of Subordinate collections.
Here's my problem: I need to get to any Employee object in the hierarchy,
based solely on its EmployeeID. I won't have a complete key path down the
hierarchy to the object. What's the best way to do this?
The obvious solution to me is to create another dictionary that contains
object references to all Employee objects, which I would use to access
employees by ID number. But is there a better solution? Thanks.
how to access an object at any point in the hierarchy, solely by its key.
The hierarchy is similar to an organizational chart, with a CEO at the top,
his/her subordinates in the next layer, their subordinates in the layer
below that, and so on. Each person is represented by an Employee object, and
Each Employee object has a Subordinates collection property (a dictionary),
which contains references to the Employee objects that represent their
subordinates, keyed by EmployeeID. So, the Employee objects are distributed
among a number of Subordinate collections.
Here's my problem: I need to get to any Employee object in the hierarchy,
based solely on its EmployeeID. I won't have a complete key path down the
hierarchy to the object. What's the best way to do this?
The obvious solution to me is to create another dictionary that contains
object references to all Employee objects, which I would use to access
employees by ID number. But is there a better solution? Thanks.