Last active
April 22, 2020 20:04
-
-
Save pascencio/9bc5616d0d9897bc261dc6154dc44621 to your computer and use it in GitHub Desktop.
Dart Mixins
This file contains hidden or 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 {} | |
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