composition/source/logic/janitor.ts
2025-03-03 06:15:30 +00:00

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()
);
}