How does Handle() work exactly? + linklist stuff

Blitz3D Forums/Blitz3D Programming/How does Handle() work exactly? + linklist stuff

octothorpe

You have a valid point. I'm talkin trash with out producing facts. Unfortunately, I continue to fail to see how your linked list example demonstrates polymorphism. I'm truly sorry.

Wouldn't polymorphism be moreso like:
Function go_for_a_walk(this.ferret)
...
End Function

Function go_for_a_walk(this.emu)
...
End Function
The advantage of using Array of Types is speed and control inside/outside of the application.

My specific ID management system consists of adding an ID Field to the Type Structure, Array of Types, Global ID_Counter, and ID assignment method.
Type obj
	Field id%
	Field value$
End Type

Dim objID.obj(100) ;array

Global objs ;id counter

Function objNew.obj()
	this.obj = New obj
	;id assignment method
	objs=objs+1
	this\id%=objs
	objID(this\id%)=this
	;set default values
	this\value="Hello World"
	Return this
End Function

;create an object
me.obj = objNew()
myself%=me\id%
i.obj = objID(myself%)

;****************************
;a handle/object version

Type obj
	Field value$
End Type

Function objNew.obj()
	this.obj = New obj
	;set default values
	this\value="Hello World"
	Return this
End Function

;create an object
me.obj = objNew()
myself%=Handle(me)
i.obj = Object.obj(myself%)
Although my system looks more complicated, I would suspect that Handle/Object are performing similar functions behind the scenes.

Control is where the technique really shines. You can assign IDs in variety of ways. I use a FIFO stack push/pop IDs. This is good for recycling IDs with objects that are created and delete constantly. I could sort the objects by ID without interupting the structure of the collection.

External Control comes in handy as well. For example in an AI Editor I create 'Trigger {ID:1}' to activate 'Door {ID:33}'. Because I know the ID of these objects before hand its easy to tell the game engine what its suppose to do with them. Additionally, I can access the properties of the object like so:
objID(myself%)\value$="Greetings World"
Print objID(myself%)\value$

;You cannot do 
Object.obj(myself%)\value$="Greetings World"
Print Object.obj(myself%)\value$
It is true that some additional code is required. Its true that some additional memory is required, but, for the level of control its worth it IMHO.