Add all 23 GoF design pattern implementations

This commit is contained in:
2026-07-25 10:50:29 +05:30
commit f5688a6b32
164 changed files with 4371 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package bridge;
/**
* Abstraction — the remote control.
*
* 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 {
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();
} 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); }
}