Here is one way...
If you want all types, you could implement some extra functionality in GetElementsByType().
One advantage to this, is that your type lists are already built, so access of those is faster.
It depends what information you need more often.
SuperStrict Framework BRL.Map Import BRL.LinkedList Import BRL.StandardIO Type TElement Const TYPE_PLAYER:Int = 1 Const TYPE_ENEMY:Int = 2 Const TYPE_BULLET:Int = 3 Global golElements:TMap = New TMap Method Init() Local id:String = GetId() Local list:TList = TList(golElements.ValueForKey(id)) If Not list Then list = New TList golElements.Insert(id, list) End If list.AddLast(Self) End Method Function GetElementsByType:TList(typeId:Int) ' can return Null TList Return TList(golElements.ValueForKey(String(typeId))) End Function Method GetId:Int() Abstract End Type Type TPlayer Extends TElement Method New() Init() End Method '.. create function etc. Method GetId:Int() Return TYPE_PLAYER End Method End Type Type TEnemy Extends TElement Method New() Init() End Method '.. create function etc. Method GetId:Int() Return TYPE_ENEMY End Method End Type Type TBullet Extends TElement Method New() Init() End Method '.. create function etc. Method GetId:Int() Return TYPE_BULLET End Method End Type 'receive all bullets: Local olBullets:TList = TElement.GetElementsByType(TElement.TYPE_BULLET) If olBullets Then Print olBullets.count() End If New TBullet New TBullet olBullets = TElement.GetElementsByType(TElement.TYPE_BULLET) Print olBullets.count()
If you want all types, you could implement some extra functionality in GetElementsByType().
One advantage to this, is that your type lists are already built, so access of those is faster.
It depends what information you need more often.