Last active
August 27, 2024 08:15
-
-
Save VladislavSoren/2314c65aaf7c18b508dd76b7ed383c4a to your computer and use it in GitHub Desktop.
design_pattern_bridge_example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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