“Java -Designmuster” Code-Antworten

Java -Designmuster

public class BinaryObserver extends Observer{

   public BinaryObserver(Subject subject){
      this.subject = subject;
      this.subject.attach(this);
   }

   @Override
   public void update() {
      System.out.println( "Binary String: " + Integer.toBinaryString( subject.getState() ) ); 
   }
}
Innocent Ibex

Java -Designmuster

public class HexaObserver extends Observer{

   public HexaObserver(Subject subject){
      this.subject = subject;
      this.subject.attach(this);
   }

   @Override
   public void update() {
      System.out.println( "Hex String: " + Integer.toHexString( subject.getState() ).toUpperCase() ); 
   }
}
Innocent Ibex

Java -Designmuster

public abstract class Observer {
   protected Subject subject;
   public abstract void update();
}
Innocent Ibex

Java -Designmuster

public class OctalObserver extends Observer{

   public OctalObserver(Subject subject){
      this.subject = subject;
      this.subject.attach(this);
   }

   @Override
   public void update() {
     System.out.println( "Octal String: " + Integer.toOctalString( subject.getState() ) ); 
   }
}
Innocent Ibex

Java -Designmuster

First state change: 15
Hex String: F
Octal String: 17
Binary String: 1111
Second state change: 10
Hex String: A
Octal String: 12
Binary String: 1010
Innocent Ibex

Ähnliche Antworten wie “Java -Designmuster”

Fragen ähnlich wie “Java -Designmuster”

Weitere verwandte Antworten zu “Java -Designmuster” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen