-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstraction_concept.dart
52 lines (39 loc) · 1.11 KB
/
abstraction_concept.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
46
47
48
49
50
51
52
import 'dart:developer';
/// The client program only knows about the Car and the functions that the Car provides.
/// The internal implementation details are hidden from the client program.
abstract class ICar {
void turnOnCar();
void turnOffCar();
String getCarType();
}
/// implementation classes of Car.
class ManualCar implements ICar {
final String _carType = "Manual";
@override
String getCarType() => _carType;
@override
void turnOffCar() => log("turn off the manual car");
@override
void turnOnCar() => log("turn on the manual car");
}
class AutomaticCar implements ICar {
final String _carType = "Automatic";
@override
String getCarType() => _carType;
@override
void turnOffCar() => log("turn off the automatic car");
@override
void turnOnCar() => log("turn on the automatic car");
}
// User Program: Let’s look at a test program
// where the Car functions will be used.
void main() {
ICar car1 = ManualCar();
ICar car2 = AutomaticCar();
car1.turnOnCar();
car1.turnOffCar();
log(car1.getCarType());
car2.turnOnCar();
car2.turnOffCar();
log(car2.getCarType());
}