Created
September 3, 2024 03:20
-
-
Save benwu232/216aadccb935717543311e75641d2624 to your computer and use it in GitHub Desktop.
mixin example for dart
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
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