| 58 | |
| 59 | === Singleton with initialization parameters === |
| 60 | Sometimes 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. |