Extended Types and Global Lists

BlitzMax Forums/BlitzMax Beginners Area/Extended Types and Global Lists

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This isn't the greatest solution to the problem but it works. Cajun17 is right this isn't an oop issue. You are trying to do is override the behavior of the Global TList in the base type which isn't how oop works. You would need a new container type. Another possiblity would be to have a function in each dervied type call GetList which would create and return a new TList with only those objects in the global list that are of the specified type. This could get slow though and would create a lot of garbage.

Type Base
	Global AllList:TList=Null
	Global ASubList:TList=Null
	Global BSubList:TList=Null
	Global CSubList:TList=Null
	
	Method New()
		If AllList=Null Then AllList=New TList
		If ASubList=Null Then ASubList=New TList
		If BSubList=Null Then BSubList=New TList
		If CSubList=Null Then CSubList=New TList
		ListAddLast AllList,Self
	End Method
	
	Method AddToSub(list:TList,o:Base)
		ListAddLast(list,o)
	End Method
	
	Method PrintList()
		If C(CSubList.first()) Then
			Print "C " + CSubList.count()
		ElseIf B(BSubList.first()) Then
			Print "B " + BSubList.count()
		ElseIf A(ASubList.first()) Then
			Print "A " + ASubList.count()
		EndIf
		Print "Base " + AllList.count()
	End Method
End Type

Type A Extends Base
	Function Create:A()
		Local o:A = New A
		o.AddToSub(ASubList,o)
		Return o
	End Function
End Type

Type B Extends A
	Function Create:B()
		Local o:B = New B
		o.AddToSub(BSubList,o)
		Return o
	End Function
	
End Type

Type C Extends A
	Function Create:C()
		Local o:C = New C
		o.AddToSub(CSubList,o)
		Return o
	End Function
	
End Type


Global aA:Base=A.Create()
Global aB:Base=A.Create()
Global aC:Base=A.Create()

Global aD:Base=B.Create()
Global aE:Base=B.Create()
Global aF:Base=B.Create()

Global aG:Base=C.Create()
Global aH:Base=C.Create()
Global aI:Base=C.Create()

aA.PrintList()
aD.PrintList()
aG.PrintList()