Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Storing non-static object in a singleton question

    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 ).

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    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.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    Wilson212 (05-24-2011)

  • #3
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •