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,33 @@
package bridge;
/**
* Abstraction — the remote control. It holds a reference to a Device
* (the "bridge") and delegates all real work to it.
*
* 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.
*/
public class RemoteControl {
// The bridge — link from Abstraction to Implementation
protected Device device;
public RemoteControl(Device device) {
this.device = device;
System.out.println("Remote paired with: " + device.getName());
}
public void togglePower() {
if (device.isEnabled()) {
device.disable();
} else {
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); }
}