forked from angular/angular.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar_creations.dart
41 lines (33 loc) · 1.1 KB
/
car_creations.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
// #docplaster
// Examples with car and engine variations
import 'car.dart';
///////// example 1 ////////////
Car simpleCar() =>
// #docregion car-ctor-instantiation
// Simple car with 4 cylinders and Flintstone tires.
new Car(new Engine(), new Tires())
// #enddocregion car-ctor-instantiation
..description = 'Simple';
///////// example 2 ////////////
// #docregion car-ctor-instantiation-with-param
class Engine2 extends Engine {
Engine2(cylinders) : super.withCylinders(cylinders);
}
Car superCar() =>
// Super car with 12 cylinders and Flintstone tires.
new Car(new Engine2(12), new Tires())
..description = 'Super';
// #enddocregion car-ctor-instantiation-with-param
/////////// example 3 //////////
// #docregion car-ctor-instantiation-with-mocks
class MockEngine extends Engine {
MockEngine() : super.withCylinders(8);
}
class MockTires extends Tires {
MockTires() { make = 'YokoGoodStone'; }
}
Car testCar() =>
// Test car with 8 cylinders and YokoGoodStone tires.
new Car(new MockEngine(), new MockTires())
..description = 'Test';
// #enddocregion car-ctor-instantiation-with-mocks