Sync Bridge to Java 25: H6 file labels, README mapping
This commit is contained in:
@@ -1,22 +1,18 @@
|
||||
package bridge;
|
||||
|
||||
/**
|
||||
* Abstraction — the remote control. It holds a reference to a Device
|
||||
* (the "bridge") and delegates all real work to it.
|
||||
* Abstraction — the remote control.
|
||||
*
|
||||
* The key: RemoteControl doesn't care whether it talks to a TV or Radio.
|
||||
* It holds a Device and calls Device methods. That's the bridge.
|
||||
* Key point: RemoteControl holds a Device (the bridge) and delegates
|
||||
* all actual work to it. It adds higher-level semantics on top:
|
||||
* "togglePower" instead of separate enable()/disable() calls.
|
||||
*/
|
||||
public class RemoteControl {
|
||||
|
||||
// The bridge — link from Abstraction to Implementation
|
||||
protected Device device;
|
||||
|
||||
protected Device device; // THE BRIDGE
|
||||
public RemoteControl(Device device) {
|
||||
this.device = device;
|
||||
System.out.println("Remote paired with: " + device.getName());
|
||||
}
|
||||
|
||||
// User action → device operation translation
|
||||
public void togglePower() {
|
||||
if (device.isEnabled()) {
|
||||
device.disable();
|
||||
@@ -24,10 +20,8 @@ public class RemoteControl {
|
||||
device.enable();
|
||||
}
|
||||
}
|
||||
|
||||
public void volumeUp() { device.setVolume(device.getVolume() + 10); }
|
||||
public void volumeDown() { device.setVolume(device.getVolume() - 10); }
|
||||
|
||||
public void channelUp() { device.setChannel(device.getChannel() + 1); }
|
||||
public void channelDown() { device.setChannel(device.getChannel() - 1); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user