Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can you have Singleton objects in VFP?
Message
From
13/07/2003 14:29:22
 
 
To
09/07/2003 09:57:03
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00808442
Message ID:
00809680
Views:
29
>Yes, I was thinking of having a class that could return references to it's own instances of the required classes.

In VFP8 it seems simple.
public goFactory
goFactory = CREATEOBJECT("cusFactory")

DEFINE CLASS cusFactory as Custom
	ADD OBJECT ioSingleton as "collection"
	FUNCTION new(tcClass,tcLib)
		WITH THIS
			IF .ioSingleton.GetKey(tcClass) = 0
				DEBUGOUT "create object"
				.ioSingleton.Add(NEWOBJECT(tcClass,tcLib),tcClass)
			ENDIF 
			DEBUGOUT "return reference"
			RETURN .ioSingleton(tcClass)
		ENDWITH 
	ENDFUNC 
ENDDEFINE
You could hang the factory off _SCREEN, or your own goApp object, however you manage such things.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform