...

View Full Version : Storing non-static object in a singleton question



Wilson212
05-22-2011, 07:02 PM
I have been coding my own Framework over the last few weeks and i have come up with a question that i cant seem to find anywhere.

I have a Registry class, which uses a singlton object to create a static version of itself. And in that singleton object, i store other objects that are requested through out the rest of the script. My question is, even though im storing Non-static classes in that singleton, when i update a variable in those classes, will they be updated when they are called again later from that instance? Basically, does the singleton instance update the class as soon as something changes, or just in the current called instance of that class ( instance being, it was called in a function ).

Dormilich
05-23-2011, 08:27 AM
as far as I remember the Registry Pattern does not need a Singleton to work with (you could say that a Registry is an extended type of singleton).

regarding the question, if you don’t destroy the (regular) objects inbetween, all changes should be kept.

Wilson212
05-24-2011, 03:41 PM
as far as I remember the Registry Pattern does not need a Singleton to work with (you could say that a Registry is an extended type of singleton).

regarding the question, if you donít destroy the (regular) objects inbetween, all changes should be kept.

After some extensive research, i was able to make a small script which set a variable in a class. I then unset that class, re-created the class under a new variable, annd was able to echo the variable i had set originally. Therfor, yes, a Registry will keep the changes you set in other places, making it a static instance pretty much :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum