Singleton (Java): Difference between revisions
From My Limbic Wiki
(Page créée avec « <syntaxhighlight lang="Java"> import java.util.*; import java.io.*; import java.math.*; class Player { public static void main(String args[]) { Scanner in =... ») |
No edit summary |
||
(14 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="Python" line='line'> | ||
/** | |||
* Implémentation simple d'un singleton. | |||
* L'instance est créée à l'initialisation. | |||
*/ | |||
public class Singleton | |||
{ | |||
/** Constructeur privé */ | |||
private Singleton() | |||
{} | |||
/** Instance unique pré-initialisée */ | |||
private static Singleton INSTANCE = new Singleton(); | |||
/** Point d'accès pour l'instance unique du singleton */ | |||
public static Singleton getInstance() | |||
{ return INSTANCE; | |||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 04:21, 30 May 2019
<syntaxhighlight lang="Python" line='line'> /**
* Implémentation simple d'un singleton. * L'instance est créée à l'initialisation. */
public class Singleton {
/** Constructeur privé */ private Singleton() {} /** Instance unique pré-initialisée */ private static Singleton INSTANCE = new Singleton(); /** Point d'accès pour l'instance unique du singleton */ public static Singleton getInstance() { return INSTANCE; }
} </syntaxhighlight>