-
Notifications
You must be signed in to change notification settings - Fork 36
/
dart.dart
45 lines (35 loc) · 936 Bytes
/
dart.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import 'src/myFile.dart';
abstract class Vehicle {
factory Vehicle(String type) {
if (type == 'skateboard') return Skateboard();
throw 'Can\'t create $type.';
}
num get odometer;
}
class Skateboard implements Vehicle {
num _odometer = 0;
num get odometer => _odometer;
Skateboard();
void addMiles(num increment) {
_odometer += increment;
}
@override
String toString() => 'Skateboard with mileage $odometer';
}
class Car implements Vehicle {
final int modelYear;
final String make;
final String model;
num _odometer = 0;
num get odometer => _odometer;
Car(this.modelYear, this.make, this.model);
void addMiles(num increment) {
_odometer += increment;
}
@override
String toString() => 'Car: $modelYear $make $model with mileage $odometer';
}
void main() {
var car = Car(2016, 'Honda', 'Civic');
print(car);
}