“Pola desain java” Kode Jawaban

Pola desain java

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

Pola desain java

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

Pola desain java

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

Pola desain java

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

Pola desain java

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

Jawaban yang mirip dengan “Pola desain java”

Pertanyaan yang mirip dengan “Pola desain java”

Lebih banyak jawaban terkait untuk “Pola desain java” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya