Skip to content

Instantly share code, notes, and snippets.

@serpicokhan
Created May 16, 2022 14:42
Show Gist options
  • Select an option

  • Save serpicokhan/e3c78f029fde4f26d26408d4ca9a82e6 to your computer and use it in GitHub Desktop.

Select an option

Save serpicokhan/e3c78f029fde4f26d26408d4ca9a82e6 to your computer and use it in GitHub Desktop.
class Musician {}
//creating a mixin
mixin Feedback {
void boo() {
print('boooing');
}
void clap() {
print('clapping');
}
}
//only classes that extend or implement the Musician class
//can use the mixin Song
mixin Song on Musician {
void play() {
print('-------playing------');
}
void stop() {
print('....stopping.....');
}
}
//To use a mixin, use the with keyword followed by one or more mixin names
class PerformSong extends Musician with Feedback, Song {
//Because PerformSong extends Musician,
//PerformSong can mix in Song
void awesomeSong() {
play();
clap();
}
void badSong() {
play();
boo();
}
}
void main() {
PerformSong().awesomeSong();
PerformSong().stop();
PerformSong().badSong();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment