Changes between Version 5 and Version 6 of SingletonPattern
- Timestamp:
- 08/23/07 22:39:02 (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
SingletonPattern
v5 v6 47 47 48 48 /* This is the mixin for a quick basic implementation of a Singleton. 49 * Note the use of a static variable local to the method. 49 * Note the use of a static variable local to the method, and the special 'typeof(this)' 50 * type expression which allows the mixin to work without knowing the class using it. 50 51 */ 51 template MSingleton ( C) {52 template MSingleton () { 52 53 53 public static Cinstance () {54 static C_instance;54 public static typeof(this) instance () { 55 static typeof(this) _instance; 55 56 56 57 if (_instance is null) 57 _instance = new C;58 _instance = new typeof(this); 58 59 59 return _insta ce;60 return _instance; 60 61 } 61 62 68 69 class Foo : ISingleton { 69 70 70 mixin MSingleton !(Foo);71 mixin MSingleton; 71 72 72 73 protected this () {