Cascade notation
void main() {
  var employee1 = Employee();
//   employee1.id = 1;
//   employee1.firstname = "John";
//   employee1.lastname = "Doe";
//   employee1.position = "CTO";
  employee1
    ..id = 1
    ..firstname = "John"
    ..lastname = "Doe"
    ..position = "CTO";
  print(employee1.toString());
}
class Employee {
  int id;
  String firstname;
  String lastname;
  String position;
  @override
  String toString() {
    return "id : $id , firstname : $firstname , lastname : $lastname, position : $position";
  }
}
void main() {
  // Cascade Notation
  var calculator1 = Calculator(3);
//   calculator1.add(12);
//   calculator1.subtract(12);
//   calculator1.add(5);
//   calculator1.subtract(9);
  calculator1
    ..add(12)
    ..subtract(12)
    ..add(5)
    ..subtract(9);
  print(calculator1.result());
}
class Calculator {
  int output = 0;
  Calculator(int startValue) {
    this.output = startValue;
  }
  void add(int val) {
    this.output += val;
  }
  void subtract(int val) {
    this.output -= val;
  }
  int result() {
    return this.output;
  }
}
Last updated
Was this helpful?
