Question class within another class

mfish02

New member
Joined
Oct 5, 2010
Messages
3
Programming Experience
1-3
I am working in VB.NET defining my own classes.

I have 5 classes, Policy, Coverage, CoverageCollection, Layer, and LayerCollection. Policy has a bunch of data items, one of which is of type CoverageCollection. Coverage has a bunch of data items, one of which is of type LayerCollection.

Policy
private id as Long
private name as String
private cov as CoverageCollection
…corresponding public properties

Coverage
private plan as String
private age as Integer
private lyr as LayerCollection
…corresponding public properties

Layer
private face as Double
private dur as Integer
…corresponding public properties

Then I do like "dim p as Policy". So, iIn order to get to properties on a Layer, I reference it like p.cov(0).lyr(0).face.

What I am trying to do is add a readonly property to Layer that is calculated using some Layer information but also using something from Coverage (or even Policy). I can take this in as a parameter to the property, but I think there should be a way to get at Coverage/Policy information since I am "under" it already. Is there a way to do this?
 
No, there is only what you have added to the class definition. The class instance knows nothing about its whereabouts.

A practical example is the Control class and ControlCollection class, where you commonly add one Control instance to the ControlCollection of another Control either though Controls property or Parent property. Parent property is the direct reference from child to parent, and it is maintained also within the ControlCollection with a private 'owner' reference that is set through the constructor. Whenever a control is added through the collection class its Parent property is also updated from the collections cached owner reference.
 
Back
Top