Can a custom object know it's owner

  • Thread starter Thread starter Usarian
  • Start date Start date
U

Usarian

I am making some custom objects that operate "inside" each other, the way a
datatable is available inside a dataset. (VB.NET 1.1)
I can't figure out how to make the child object know what object it's inside
of.

What I have is a custom object called Ageload which contains a custom
collection designed to hold another custom object called a Batch.
(Ageload, BatchCollection, Batch)

When I use a dataset with a table in it, I can do something like:
Datatable.Dataset (and get a reference to the dataset and all of it's
functions/properties)

I want to make my Ageloads and Batches do the same thing:
Batch.Ageload (and get a reference to the Ageload)

Thanks!

Usarian
 
Simply store a reference to the object in the child object. When you create
the child object, pass in the parent instance to initialize it. i.e.:



Public Class ParentClass

End Class


Public Class ChildClass

Private m_Parent As ParentClass = Nothing

Public Readonly Property MyParent As ParentClass

Get
return m_Parent
End Get

End Property



Public Sub New ( byval theParent As ParentClass )

m_Parent = theParent

End Sub

End Class
 
I might have to do it that way. I'm already passing in about 6 values, and
wanted avoid making it any larger. Collections are new to me, so I thought
that they might know who owns them. (But the Batch itself still wouldn't
know it was in a collection anyway, so I'm still in the same boat.)

I have to wonder how they made the datatable know what dataset contains it
without passing that information in.


Anyway, Thanks!
Usarian
 
I have to wonder how they made the datatable know what dataset contains it
without passing that information in.


Anyway, Thanks!
Usarian

You can be sure that information is passed through somewhere during
construction, perhaps behind the scenes.
 
Back
Top