Skip to content

Instantly share code, notes, and snippets.

@mariopepe
Created April 1, 2020 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariopepe/45701a9ddae2fe22a124b648e8f2a2ad to your computer and use it in GitHub Desktop.
Save mariopepe/45701a9ddae2fe22a124b648e8f2a2ad to your computer and use it in GitHub Desktop.
Class exploration in Dart - skinny dude section 2 up until video 25
/// Main
void main() {
final personOne = Person(name: "Mario", age: 23, height: 1.83);
print(personOne.describePerson());
final employeeOne = Employee(
name: "Mario",
age: 23,
height: 1.83,
taxcode: "XOXOOOXXO",
salary: 50000);
print(employeeOne.describeEmployee());
print(employeeOne.toString());
}
/// Class definition
class Person {
Person({
this.name,
this.age,
this.height,
});
final String name;
final int age;
final double height;
@override
String toString() {
return 'name: $name, age: $age, height: $height';
}
String describePerson() {
return ("My name is $name, I am $age years old"
"and I am $height meters tall.\n");
}
}
class Employee extends Person {
Employee({
String name,
int age,
double height,
this.taxcode,
this.salary,
}) : super(
name: name,
age: age,
height: height,
);
final String taxcode;
final int salary;
@override
String toString() {
return '${super.toString()}, taxcode: $taxcode, salary: $salary';
}
String describeEmployee() {
return ("${super.describePerson()}I am also an employee with"
" tax code $taxcode, and I earn $salary € per month.\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment