Substitute for Parent()

BlitzMax Forums/BlitzMax Beginners Area/Substitute for Parent()

GuntiNDDS(Posted 2010) [#1]
Does BlitzMax provide an elegant way to get the parent object of an object, like Self.Parent() ?

I know i could code it myself like this:
Type TParent
	Field _Child:TChild = New TChild
	Method Init()
		Self._Child.SetParent(Self)
	End Method
	Method Test()
		Print "I have been invoked by my child."
	End Method
EndType

Type TChild
	Field _Parent:TParent = Null
	Method SetParent(paParent:TParent)
		_Parent = paParent
		_Parent.Test()
	End Method
End Type


Local myParent:TParent = New TParent
myParent.Init()


but i dont like all the overhead.


Thanks.


Dreamora(Posted 2010) [#2]
There is no such thing as a parent unless your code has child and parents and if so, you have to provide references to them as distinct objects have no relationship without references.
Thats in all languages a thing you have to implement yourself cause its something that only exists in your OO hierarchy

perhaps you are mixing parent with parent class which is not the same and does in no way have a relation to the example code you show?


GuntiNDDS(Posted 2010) [#3]
I am looking for an automated reference that points to the object that has created the object. like my code above but with less overhead


Dreamora(Posted 2010) [#4]
That does not exist and I'm not aware of any language thats somewhere modern and common (and compiled) that offers such a thing.

The common term if it was about reference counts etc by the way would be owner, wouldn't it?


Czar Flavius(Posted 2010) [#5]
You might as well put the Init code in the New method, which is ran automatically for you.