Last active
April 20, 2018 09:03
-
-
Save thonglinhma/7631ea06fc972025eb376142bf6b78a7 to your computer and use it in GitHub Desktop.
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
| abstract class Switch { | |
| Appliance appliance; | |
| void turnOn(); | |
| } | |
| abstract class Appliance { | |
| void run(); | |
| } | |
| class RemoteControl extends Switch { | |
| Appliance appliance; | |
| RemoteControl({this.appliance}); | |
| @override | |
| void turnOn() { | |
| this.appliance.run(); | |
| } | |
| } | |
| class TV extends Appliance { | |
| @override | |
| void run() { | |
| print("tv turned on"); | |
| } | |
| } | |
| class VacuumClearner extends Appliance { | |
| @override | |
| void run() { | |
| print("vacuum cleaner turned on"); | |
| } | |
| } | |
| main(List<String> arguments) { | |
| final tvRemoteControl = new RemoteControl(appliance: new TV()); | |
| tvRemoteControl.turnOn(); | |
| final vacuumRemoteControl = new RemoteControl(appliance: new VacuumClearner()); | |
| vacuumRemoteControl.turnOn(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment