Created with <3 with dartpad.dev.
Last active
July 9, 2023 16:30
-
-
Save ihsanberahim/9c7a74d867af2e8d2ad741762fb54b70 to your computer and use it in GitHub Desktop.
elegant-marble-1300
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
class Animal { | |
String name; | |
int age; | |
Animal(this.name, this.age); | |
void speak() { | |
print('I am an animal'); | |
} | |
} | |
class Dog extends Animal with AnimalSound, AnimalBehavior { | |
String sound = 'woof'; | |
Dog(String name, int age) : super(name, age); | |
@override | |
void speak() { | |
print('I am a dog'); | |
print('I say ${this.sound}'); | |
} | |
} | |
mixin AnimalSound { | |
String sound = ''; | |
void makeSound() { | |
print('I make the sound ${this.sound}'); | |
} | |
} | |
mixin AnimalBehavior { | |
String behavior = ''; | |
void makeBehavior() { | |
print('I make the behavior ${this.behavior}'); | |
} | |
} | |
void main() { | |
var dog = Dog('Spot', 3); | |
dog.speak(); | |
dog.makeSound(); | |
dog.makeBehavior(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment