Created
May 16, 2022 14:42
-
-
Save serpicokhan/e3c78f029fde4f26d26408d4ca9a82e6 to your computer and use it in GitHub Desktop.
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
| 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