in reply to Re: Re (tilly) 2: Use globals or pass around everything under the sun?
in thread Use globals or pass around everything under the sun?

The Singleton pattern is really quite simple. What you do is have a class with a private constructor that nobody ever calls. The public constructor calls the private constructor only on the first time it is called, memoizes the answer, and hands it back every time after that.

The result is a class which will only have a single instance no matter how many places you ask for it. (The trick isn't in figuring out how to do it, it is in figuring out when doing it is a really useful thing...)

  • Comment on Re (tilly) 4: Use globals or pass around everything under the sun?