桥模式( 四 )

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

.java
public class ConcreteRemote extends RemoteControl {private int currentStation = 0;private final int MAX_STATION = 25;public ConcreteRemote(TV _tv) {super(_tv);}@Overridepublic void on() {tv.on();}@Overridepublic void off() {tv.off();}public void setChannel(int channel) {currentStation = channel;super.setChannel(currentStation);}public void nextChannel() {currentStation = (MAX_STATION + currentStation + 1) % MAX_STATION;super.setChannel(currentStation);}public void previousChannel() {currentStation = (MAX_STATION + currentStation - 1) % MAX_STATION;super.setChannel(currentStation);}}