Skip to content

Instantly share code, notes, and snippets.

@pascencio
Last active April 22, 2020 20:04
Show Gist options
  • Save pascencio/9bc5616d0d9897bc261dc6154dc44621 to your computer and use it in GitHub Desktop.
Save pascencio/9bc5616d0d9897bc261dc6154dc44621 to your computer and use it in GitHub Desktop.
Dart Mixins
abstract class Animal {}
abstract class Mamal extends Animal { }
abstract class Bird extends Animal { }
abstract class Fish extends Animal { }
abstract class Walker {
void walk() => print("Im walking");
}
abstract class Swimer {
void swim() => print("Im swiming");
}
abstract class Flyer {
void fly() => print("Im flying");
}
class Dolphin extends Mamal with Swimer {
}
class Bat extends Mamal with Walker, Flyer {
}
class Cat extends Mamal with Walker {
}
class Dove extends Bird with Walker, Flyer {
}
class Duck extends Bird with Walker, Flyer, Swimer {
}
class Shark extends Fish with Swimer {
}
class FlyingFish extends Fish with Swimer, Flyer {
}
void main(){
final duck = new Duck();
duck.fly();
duck.swim();
duck.walk();
final flyingFish = new FlyingFish();
flyingFish.fly();
flyingFish.swim();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment