Created
April 8, 2022 18:56
-
-
Save johnpryan/011eae018c16b53e64f736afedb20c5b to your computer and use it in GitHub Desktop.
Dart mixin precedence
This file contains 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
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