Skip to content

Instantly share code, notes, and snippets.

@VladislavSoren
Last active August 27, 2024 08:15
Show Gist options
  • Select an option

  • Save VladislavSoren/2314c65aaf7c18b508dd76b7ed383c4a to your computer and use it in GitHub Desktop.

Select an option

Save VladislavSoren/2314c65aaf7c18b508dd76b7ed383c4a to your computer and use it in GitHub Desktop.
design_pattern_bridge_example
class Remote:
def __init__(self, device):
self.device = device
def volumeDown(self):
volume_now = self.device.getVolume()
volume_new = volume_now - 10
self.device.setVolume(volume_new)
class AdvancedRemote(Remote):
def mute(self):
self.device.setVolume(0)
class Device:
def __init__(self, volume_default=0):
self.volume = volume_default
def setVolume(self, volume_new):
self.volume = volume_new
def getVolume(self):
return self.volume
device = Device(volume_default=20)
remote = Remote(device)
remote.volumeDown()
print(device.volume)
advanced_remote = AdvancedRemote(device)
advanced_remote.mute()
print(device.volume)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment