Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes between Version 5 and Version 6 of SingletonPattern

Show
Ignore:
Author:
csauls (IP: 76.177.172.234)
Timestamp:
08/23/07 22:39:02 (17 years ago)
Comment:

Fixed another typo -- instace -> instance -- and updated the mixin examples to use 'typeof(this)' -- simplifies usage.

Legend:

Unmodified
Added
Removed
Modified
  • SingletonPattern

    v5 v6  
    4747 
    4848/* 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. 
    5051 */ 
    51 template MSingleton (C) { 
     52template MSingleton () { 
    5253 
    53   public static C instance () { 
    54     static C _instance; 
     54  public static typeof(this) instance () { 
     55    static typeof(this) _instance; 
    5556 
    5657    if (_instance is null) 
    57       _instance = new C
     58      _instance = new typeof(this)
    5859 
    59     return _instace; 
     60    return _instance; 
    6061  } 
    6162 
    6869class Foo : ISingleton { 
    6970 
    70   mixin MSingleton!(Foo)
     71  mixin MSingleton
    7172 
    7273  protected this () {