Obtain reference to Parent object during instantiation

Posted by GoldBishop on Programmers See other posts from Programmers or by GoldBishop
Published on 2012-12-03T16:52:04Z Indexed on 2012/12/03 17:18 UTC
Read the original article Hit count: 251

Filed under:
|

I have a situation where a custom class is a property of another class.

What i need to be able to do, if it is possible at all, is obtain a reverse to the "parent" class (ie the the class that holds the current class as a property).

For Instance:

Public Class Class1
  ...
  public readonly property Prop11 as Class2
  public property Prop12 as String
  ...
End Class

Public Class Class2
  ...
  private _par as Class1
  private _var21 as string
  ...
  Public Sub New(...)
    me._par = ????
    ...
  End Sub
  public readonly property Prop21 as string
    Get
      return me._par.Prop12 & me._var21
    End Get
  End Property
  ...
End Class

Ultimately, i am trying to access other properties within Class1 from Class2 as they do have substance for information from within Class2. There are several other classes within Class1 that provide descriptive information to other classes contained within it as properties but the information is not extensible to all of the classes through Inheritance, as Class1 is being used as a resource bin for the property classes and the application itself.

Diagram, lazy design ;):

Application <- Class1.Prop12
Application <- Class1.Prop11.Prop21

Question:

  1. Is it possible to get a recursion through this design setup?

© Programmers or respective owner

Related posts about .NET

Related posts about vb.net