Add all 23 GoF design pattern implementations (2026-06-13)

This commit is contained in:
Ankur
2026-06-13 21:44:56 +05:30
commit a5beb61425
106 changed files with 2977 additions and 0 deletions

View 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"; }
}