Last active
December 17, 2019 00:28
-
-
Save aabeben/700fbcdd2f8d10c3908ba0bc262652f9 to your computer and use it in GitHub Desktop.
Mixins
This file contains 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
// Mixins adalah cara agar kode dapat digunakan berulang-ulang | |
// pada hirarki kelas lebih dari satu. | |
// Kelas berikut berfungsi sebagai mixin: | |
class Piloted { | |
int astronauts = 1; | |
void descriveCrew(){ | |
print('Number of astronauts: $astronauts'); | |
} | |
} | |
// Untuk menambahkan kemampuan-kemampuan kepada kelas, cukup panjangkan kelas tersebut dengan mixin. | |
class PilotedCraft extends Spacecraft with Piloted{ | |
// ... | |
} | |
// Sekarang PilotedCraft mempunyai medan astronauts dan juga metode describeCrew(). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment