forked from angular/angular.io
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcar.services.ts
95 lines (82 loc) · 1.93 KB
/
car.services.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { Injectable } from '@angular/core';
/// Model ///
export class Car {
name = 'Avocado Motors';
constructor(public engine: Engine, public tires: Tires) { }
get description() {
return `${this.name} car with ` +
`${this.engine.cylinders} cylinders and ${this.tires.make} tires.`;
}
}
export class Engine {
cylinders = 4;
}
export class Tires {
make = 'Flintstone';
model = 'Square';
}
//// Engine services ///
@Injectable()
export class EngineService {
id = 'E1';
getEngine() { return new Engine(); }
}
@Injectable()
export class EngineService2 {
id = 'E2';
getEngine() {
const eng = new Engine();
eng.cylinders = 8;
return eng;
}
}
//// Tire services ///
@Injectable()
export class TiresService {
id = 'T1';
getTires() { return new Tires(); }
}
/// Car Services ///
@Injectable()
export class CarService {
id = 'C1';
constructor(
protected engineService: EngineService,
protected tiresService: TiresService) { }
getCar() {
return new Car(
this.engineService.getEngine(),
this.tiresService.getTires());
}
get name() {
return `${this.id}-${this.engineService.id}-${this.tiresService.id}`;
}
}
@Injectable()
export class CarService2 extends CarService {
id = 'C2';
constructor(
protected engineService: EngineService,
protected tiresService: TiresService) {
super(engineService, tiresService);
}
getCar() {
const car = super.getCar();
car.name = 'BamBam Motors, BroVan 2000';
return car;
}
}
@Injectable()
export class CarService3 extends CarService2 {
id = 'C3';
constructor(
protected engineService: EngineService,
protected tiresService: TiresService) {
super(engineService, tiresService);
}
getCar() {
const car = super.getCar();
car.name = 'Chizzamm Motors, Calico UltraMax Supreme';
return car;
}
}