50 lines
618 B
TypeScript
50 lines
618 B
TypeScript
class Janitor implements Employee {
|
|
private identity: Identity;
|
|
private occupations: Array<Occupation>;
|
|
|
|
public constructor(name: string) {
|
|
this.identity = new Identity("janitor", name);
|
|
this.occupations = [
|
|
new Repairing(),
|
|
new Cleaning(),
|
|
];
|
|
}
|
|
|
|
public introduce(): void {
|
|
this.identity.introduce();
|
|
}
|
|
public work(): void {
|
|
for (const occupation of this.occupations) {
|
|
occupation.work();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function makeJanitor(name: string): Employee {
|
|
return compose(
|
|
compose(
|
|
new Identity("smartly composed janitor", name),
|
|
new Repairing()
|
|
),
|
|
new Cleaning()
|
|
);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|