Skip to content

Instantly share code, notes, and snippets.

@johnpryan
Created April 8, 2022 18:56
Show Gist options
  • Save johnpryan/011eae018c16b53e64f736afedb20c5b to your computer and use it in GitHub Desktop.
Save johnpryan/011eae018c16b53e64f736afedb20c5b to your computer and use it in GitHub Desktop.
Dart mixin precedence
void main() {
var animal = Bird();
print(animal.nextAction());
}
abstract class Animal {
String get name;
// 4th precedence
String makeNoise() => '(uninteligble animal sound)';
String nextAction() => 'the $name went ${makeNoise()}.';
}
class Bird extends Animal with Consumer, Flyer {
@override
final name = 'bird';
// 1st precedence
// @override
// String makeNoise() => "squak";
}
mixin Consumer {
// 3rd precedence
// String makeNoise() => "chomp";
}
mixin Flyer {
// 2nd precedence
// String makeNoise() => "flap";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment