//Titel:            Testbeispiel fuer das Design Pattern Singleton
//Version:          05.05.2013
//Copyright:        HS-Harz, FB AI
//Autor:            Dipl.-Inf.(TU) Dipl.-Ing.(FH) Michael Wilhelm
//Firma:            HS-Harz
//Beschreibung:     Singleton mit enums



import java.io.*;



public class Singleton_enum {


  private static void pause() {
    try {
      System.in.read();
    }
    catch (IOException e) {
    }
  }  // pause


 static void test() {
     Singleton  c = Singleton.INSTANCE;
     System.out.println("c: "+ c.getValue()  );
 }

 static public void main(String[] args) {
    System.out.println(" ");
    System.out.println(" ");
    
    Singleton  a  = Singleton.INSTANCE;
    System.out.println("a: "+ a.getValue()  );
    a.setValue(2222);
    System.out.println(" ");
    System.out.println(" ");
    
    Singleton  b = Singleton.INSTANCE;
    b.setValue(1111);
    System.out.println("a: "+ a.getValue()  );
    System.out.println("b: "+ b.getValue()  );
    System.out.println(" ");
    test();
    pause();
 }


}


 enum Singleton {
    INSTANCE;

    private int i=33;

    private Singleton() {
      this(0);
    }
    private Singleton(int i) {
      System.out.println("i im Konstruktor: "+this.i);
      this.i = i;
    }
    public int getValue() {
      return i;
    }
    public void setValue(int value) {
      i = value;
    }


}
