Duplicate Singletons

BlitzMax Forums/BlitzMax Programming/Duplicate Singletons

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.

@Muttley: Found a bug in the singleton class. You can create several instances of a class if not using the create function (just New)
I've changed to this:
Type TSingleton

	Global instance:TSingleton		' This holds the singleton instance of this Type
		
'#Region Constructors
	Method New()
		If instance Throw "Cannot create multiple instances of Singleton Type"
		instance = Self
	EndMethod

	Function Create:TSingleton()
		Return TSingleton.GetInstance()
	End Function
	
	Function GetInstance:TSingleton()
		If Not instance
			Return New TSingleton
		Else
			Return instance
		EndIf
	EndFunction
'#End Region 
	
EndType

Notice the instance = self in the new method. I'll update this on the next BLIde version.