“Java Design Patterns” Ответ

Java Design Patterns

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 Design Patterns

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 Design Patterns

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

Java Design Patterns

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 Design Patterns

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

Ответы похожие на “Java Design Patterns”

Вопросы похожие на “Java Design Patterns”

Больше похожих ответов на “Java Design Patterns” по Java

Смотреть популярные ответы по языку

Смотреть другие языки программирования