Type Dependencies

BlitzMax Forums/BlitzMax Beginners Area/Type Dependencies

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.

I only like to pass parameters to a method if I will be calling the method with different values for the parameters. In this case I would be passing the same array every time. The fact that the method will always operate on the same array should be built into the method .
In that case you need a "Singleton".
Strict

Type SingletonExample Final
	Global myInstance:SingletonExample

	Method New()
		If myInstance <> Null
			RuntimeError "Singleton creation error"
		EndIf
	EndMethod 

	Function getInstance:SingletonExample()
		If myInstance = Null
			myInstance = New SingletonExample
		EndIf
		Return myInstance
	EndFunction
EndType
It's not a "true" singleton (since BlitzMAX doesn't allow for Private constructors, meaning you can (in theory) instantiate more than one Singleton), but it works similar enough to one. To use it,use "SingletonExample.getInstance()" and you'll have access to any public fields or methods included in the singleton object.