Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can you have Singleton objects in VFP?
Message
De
13/07/2003 14:29:22
 
 
À
09/07/2003 09:57:03
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00808442
Message ID:
00809680
Vues:
31
>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform