Skip to content

Instantly share code, notes, and snippets.

@benwu232
Created September 3, 2024 03:20
Show Gist options
  • Save benwu232/216aadccb935717543311e75641d2624 to your computer and use it in GitHub Desktop.
Save benwu232/216aadccb935717543311e75641d2624 to your computer and use it in GitHub Desktop.
mixin example for dart
abstract class Animal {
void breath() {
print('breathing');
}
}
mixin Swim {
void swim() {
print('swimming');
}
}
class Whale extends Animal with Swim{
String feature = 'lung';
void hasLung() {
print('has lung');
}
void describe() {
print('Here is an animal');
print(feature);
hasLung();
swim();
}
}
class Fish extends Animal with Swim {
String feature = 'gill';
void hasGill() {
print('has gill');
}
void describe() {
print('Here is a fish');
print(feature);
hasGill();
swim();
}
}
void main() {
var whale = Whale();
whale.describe();
var fish = Fish();
fish.describe();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment