1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| public class Information
{
/***********************************************
* Exemple d'implémentation d'un Singleton *
***********************************************/
// Instance unique créée au chargement de la classe
public static Information instance = new Information();
// Méthode de classe pour accéder à ton instance
public static getInstance()
{
return instance;
}
// Constructeur en privé pour empécher son appel
// en dehors de cette classe
private Information()
{
this.properties = new HashMap();
}
/***********************************************/
// Méthode statique pour pouvoir recharger tes informations
public static load(String filePath)
{
Information information = getInstance();
// Lire ton fichier pour charger des propriétés
...
information.putProperty(readName, readValue);
...
}
public putProperty(String name, Object value)
{
this.properties.put(name, value);
}
public Object getProperty(String name)
{
return this.properties.get(name);
}
// Variable d'instance qui contient tes propriétés
private Map properties;
} |
Partager