Changes between Version 1 and Version 2 of SingletonHowto


Ignore:
Timestamp:
Mar 11, 2010, 1:37:37 PM (15 years ago)
Author:
Till Crueger
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SingletonHowto

    v1 v2  
    5656       CONSTRUCT_SINGLETON(MySingletonExample) // no ; after this
    5757     }}}
     58
     59=== Singleton with initialization parameters ===
     60Sometimes it is necessary for a singleton to be passed some initilization parameters. For example the UIFactory mentioned above needs to know what kind of user interface it has to produce. Making a singleton that takes initialization parameters is only sligtly different from the steps lined out above. Here are all the differences:
     61
     62 * pass an extra {{{false}}} to the template to deactivate the standard instantiation mechanism
     63 * write a method that handles the special parameters and instantiation. In this method you can use the {{{setInstance(T*)}}} method inherited from the singleton pattern to set the created instance. The {{{setInstance()}}} method will only work when the {{{false}}} template parameter has been set and produce errors otherwise.
    5864