Add all 23 GoF design pattern implementations (2026-06-13)
This commit is contained in:
29
02-structural/bridge/Radio.java
Normal file
29
02-structural/bridge/Radio.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package bridge;
|
||||
|
||||
/**
|
||||
* Concrete Implementor — a radio.
|
||||
* Same Device interface, completely different internal behaviour.
|
||||
*/
|
||||
public class Radio implements Device {
|
||||
|
||||
private boolean on = false;
|
||||
private int volume = 20;
|
||||
private int channel = 1; // FM frequency index simplified
|
||||
|
||||
@Override public boolean isEnabled() { return on; }
|
||||
@Override public void enable() { on = true; System.out.println(" [Radio] Powered ON"); }
|
||||
@Override public void disable() { on = false; System.out.println(" [Radio] Powered OFF"); }
|
||||
|
||||
@Override
|
||||
public int getVolume() { return volume; }
|
||||
|
||||
@Override
|
||||
public void setVolume(int percent) {
|
||||
this.volume = Math.max(0, Math.min(100, percent));
|
||||
System.out.println(" [Radio] Volume set to " + this.volume);
|
||||
}
|
||||
|
||||
@Override public int getChannel() { return channel; }
|
||||
@Override public void setChannel(int ch) { this.channel = ch; System.out.println(" [Radio] Frequency -> " + ch); }
|
||||
@Override public String getName() { return "JBL Radio"; }
|
||||
}
|
||||
Reference in New Issue
Block a user