Created
September 2, 2022 21:53
-
-
Save SamJakob/e52b3c0917d19f2dcd763644c51ce6d4 to your computer and use it in GitHub Desktop.
Dart Extensions example
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
/// Library A | |
class Animal { | |
final String name; | |
const Animal({ required this.name }); | |
} | |
class Dog extends Animal { | |
final String breed; | |
const Dog({ required String name, required this.breed }) | |
: super(name: name); | |
} | |
/// Your program | |
void main() { | |
final astro = Dog(name: 'Astro', breed: 'German Shephard'); | |
print(astro.name); | |
astro.bark(); | |
} | |
/// Library B | |
extension DogAction on Dog { | |
void bark() { | |
print('Woof!'); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment