Skip to content

Instantly share code, notes, and snippets.

@gyugyu90
Last active October 16, 2024 13:52
Show Gist options
  • Save gyugyu90/eabefd52aa096f63e9a2d8485c33852f to your computer and use it in GitHub Desktop.
Save gyugyu90/eabefd52aa096f63e9a2d8485c33852f to your computer and use it in GitHub Desktop.
class Headphone {
double volume = 5;
void increaseVolume() {
if (volume == 10) {
print('최고 볼륨입니다!');
return;
}
volume++;
}
void decreaseVolume() {
if (volume == 0) {
print('최저 볼륨입니다!');
return;
}
volume++;
}
}
class BluetoothHeadphone extends Headphone {
bool isPlaying = false;
void togglePlay() {
isPlaying = !isPlaying;
}
}
class NoiseCancellingHeadphone extends BluetoothHeadphone {
bool noiseCancellingEnabled = false;
void toggleNoiseCancelling() {
noiseCancellingEnabled = !noiseCancellingEnabled;
}
}
void main() {
BluetoothHeadphone bluetoothHeadphone = BluetoothHeadphone();
bluetoothHeadphone.increaseVolume();
print(bluetoothHeadphone.volume); // 6
bluetoothHeadphone.togglePlay();
print(bluetoothHeadphone.isPlaying); // false
NoiseCancellingHeadphone noiseCancellingHeadphone =
NoiseCancellingHeadphone();
noiseCancellingHeadphone.decreaseVolume();
print(noiseCancellingHeadphone.volume); // 4
noiseCancellingHeadphone.togglePlay();
print(noiseCancellingHeadphone.isPlaying); // true
noiseCancellingHeadphone.toggleNoiseCancelling();
print(noiseCancellingHeadphone.noiseCancellingEnabled); // true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment