Skip to content

Instantly share code, notes, and snippets.

@thonglinhma
Last active April 20, 2018 09:03
Show Gist options
  • Select an option

  • Save thonglinhma/7631ea06fc972025eb376142bf6b78a7 to your computer and use it in GitHub Desktop.

Select an option

Save thonglinhma/7631ea06fc972025eb376142bf6b78a7 to your computer and use it in GitHub Desktop.
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