|
3 | 3 | import 'car.dart';
|
4 | 4 |
|
5 | 5 | ///////// example 1 ////////////
|
6 |
| -Car simpleCar() { |
7 |
| - //#docregion car-ctor-instantiation |
| 6 | +Car simpleCar() => |
| 7 | + // #docregion car-ctor-instantiation |
8 | 8 | // Simple car with 4 cylinders and Flintstone tires.
|
9 |
| - var car = new Car(new Engine(), new Tires()); |
10 |
| - //#enddocregion car-ctor-instantiation |
11 |
| - car.description = 'Simple'; |
12 |
| - return car; |
13 |
| -} |
14 |
| -///////// example 2 //////////// |
| 9 | + new Car(new Engine(), new Tires()) |
| 10 | + // #enddocregion car-ctor-instantiation |
| 11 | + ..description = 'Simple'; |
15 | 12 |
|
16 |
| -//#docregion car-ctor-instantiation-with-param |
17 |
| -class Engine2 implements Engine { |
18 |
| - final int cylinders; |
| 13 | +///////// example 2 //////////// |
19 | 14 |
|
20 |
| - Engine2(this.cylinders); |
21 |
| -} |
22 |
| -//#enddocregion car-ctor-instantiation-with-param |
23 |
| - |
24 |
| -Car superCar() { |
25 |
| -//#docregion car-ctor-instantiation-with-param |
26 |
| -// Super car with 12 cylinders and Flintstone tires. |
27 |
| -var bigCylinders = 12; |
28 |
| -var car = new Car(new Engine2(bigCylinders), new Tires()); |
29 |
| -//#enddocregion car-ctor-instantiation-with-param |
30 |
| - car.description = 'Super'; |
31 |
| - return car; |
| 15 | +// #docregion car-ctor-instantiation-with-param |
| 16 | +class Engine2 extends Engine { |
| 17 | + Engine2(cylinders) : super.withCylinders(cylinders); |
32 | 18 | }
|
| 19 | + |
| 20 | +Car superCar() => |
| 21 | + // Super car with 12 cylinders and Flintstone tires. |
| 22 | + new Car(new Engine2(12), new Tires()) |
| 23 | + ..description = 'Super'; |
| 24 | +// #enddocregion car-ctor-instantiation-with-param |
| 25 | + |
33 | 26 | /////////// example 3 //////////
|
34 | 27 |
|
35 |
| -//#docregion car-ctor-instantiation-with-mocks |
| 28 | +// #docregion car-ctor-instantiation-with-mocks |
36 | 29 | class MockEngine extends Engine {
|
37 |
| - final int cylinders = 8; |
| 30 | + MockEngine() : super.withCylinders(8); |
38 | 31 | }
|
39 | 32 |
|
40 | 33 | class MockTires extends Tires {
|
41 |
| - String make = 'YokoGoodStone'; |
| 34 | + MockTires() { make = 'YokoGoodStone'; } |
42 | 35 | }
|
43 | 36 |
|
44 |
| -//#enddocregion car-ctor-instantiation-with-mocks |
45 |
| -Car testCar() { |
46 |
| -//#docregion car-ctor-instantiation-with-mocks |
47 |
| -// Test car with 8 cylinders and YokoGoodStone tires. |
48 |
| -var car = new Car(new MockEngine(), new MockTires()); |
49 |
| -//#enddocregion car-ctor-instantiation-with-mocks |
50 |
| - car.description = 'Test'; |
51 |
| - return car; |
52 |
| -} |
| 37 | +Car testCar() => |
| 38 | + // Test car with 8 cylinders and YokoGoodStone tires. |
| 39 | + new Car(new MockEngine(), new MockTires()) |
| 40 | + ..description = 'Test'; |
| 41 | +// #enddocregion car-ctor-instantiation-with-mocks |
0 commit comments