Dart Cascade Example
This is a simple Dart program demonstrating the use of the cascade notation (..) in object-oriented programming. It shows how you can perform multiple operations on the same object without repeating the object name.
Features
- Demonstrates the use of cascade notation in Dart
- Modifies object properties and calls methods on the same object in a compact syntax
- Displays the details of a
Carobject
Code Example
class Car {
String brand;
String model;
int year;
// Constructor
Car(this.brand, this.model, this.year);
// Method to display car details
void display() {
print('Car: $brand $model ($year)');
}
}
void main() {
// Using cascade notation to set values and call methods
var myCar = Car('Toyota', 'Corolla', 2020)
..brand = 'Honda'
..model = 'Civic'
..year = 2022
..display(); // Displays: Car: Honda Civic (2022)
}