Skip to content

Instantly share code, notes, and snippets.

@ihsanberahim
Last active July 9, 2023 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihsanberahim/9c7a74d867af2e8d2ad741762fb54b70 to your computer and use it in GitHub Desktop.
Save ihsanberahim/9c7a74d867af2e8d2ad741762fb54b70 to your computer and use it in GitHub Desktop.
elegant-marble-1300
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