Last active
August 19, 2021 03:22
-
-
Save nmccready/00d11c8a7974510c67515e323beabc61 to your computer and use it in GitHub Desktop.
Dart Notes
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
void main() { | |
final p = new Employee("Nick", height: 5.8, weight: 210, age: 41, taxCode: "123", salary: 2000000); | |
print(p.toString()); | |
} | |
mixin Health { | |
String getLifePercentage(int age) => (100 * (age / 101.00)).toStringAsFixed(3); | |
double getBMI(double height, double weight) => weight / (height * height); | |
} | |
class Person with Health { | |
final String name; | |
final int age; | |
final double height; | |
final double weight; | |
Person(this.name, { this.age, this.height, this.weight = 0.0 }); | |
String toString() => "name: $name, age: $age, height: $height, bmi: $bmi, life: $lifePercent"; | |
double get bmi => getBMI(this.height, this.weight); | |
String get lifePercent => getLifePercentage(this.age); | |
} | |
class Employee extends Person { | |
final String taxCode; | |
final int salary; | |
Employee(String name, {int age, double height, double weight, this.taxCode, this.salary}) : | |
super(name, age: age, height: height, weight: weight); | |
String toString() => "${super.toString()} taxCode: $taxCode, salary: $salary"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mixins are kinda slick