For those who do not already know what Single is, here's a definition:
Quote
Anyone else use this design pattern? If so what do you use it for and how do you implement it? Discuss
Posted 16 December 2009 - 11:01 AM
Quote
Posted 16 December 2009 - 11:15 AM
This post has been edited by markhazlett9: 16 December 2009 - 11:15 AM
Posted 16 December 2009 - 11:27 AM
This post has been edited by KYA: 16 December 2009 - 11:29 AM
Posted 16 December 2009 - 11:35 AM
PsychoCoder, on 16 Dec, 2009 - 05:01 PM, said:
Posted 16 December 2009 - 11:35 AM
class world {
public static List<string> arguments;
public static bool ArgExists(string argName) { /*blah*/ return result; }
public static string GetArgValue(string argName, int offset) { /*blah*/ return "value"; }
}
`
Posted 16 December 2009 - 12:05 PM
EdwinNameless, on 16 Dec, 2009 - 09:35 AM, said:
Posted 16 December 2009 - 12:08 PM
Posted 16 December 2009 - 09:03 PM
This post has been edited by eclipsed4utoo: 16 December 2009 - 09:08 PM
Posted 17 December 2009 - 12:05 AM
Posted 17 December 2009 - 02:06 AM
PsychoCoder, on 16 Dec, 2009 - 06:05 PM, said:
Posted 17 December 2009 - 12:01 PM
Posted 17 December 2009 - 06:06 PM
Posted 18 December 2009 - 03:10 AM
SoundManager->Instance()->PlaySound("file");
Posted 18 December 2009 - 12:25 PM
private static volatile T _instance; private static object _synch = new object();
//check for an instance, if one isnt there
//then lock and create an instance
if (_instance == null)
{
lock (_synch)
{
if (_instance == null)
{
//do your work here
}
}
}
public abstract class Singleton<T> where T : class
{
}
public class MyClass : Singleton<MyClass>
{
}
public static MyClass Instance
{
get { return Singleton<MyClass>.Instance; }
}
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
