diff --git a/src/task_1/index.ts b/src/task_1/index.ts index b694a65..b8cc219 100644 --- a/src/task_1/index.ts +++ b/src/task_1/index.ts @@ -27,8 +27,26 @@ import { EmployeeDivision } from "../empoyee-separate.enum"; */ export abstract class BaseEmployee { + protected constructor(private fullName: string, private department: EmployeeDivision) { + this.fullName=fullName; + this.department=department; + } + public getName(): string{ + return this.fullName; + } + + public getDepartment(): EmployeeDivision{ + return this.department; + } + + abstract getAuthority(): void; } -export interface IManageEmployee { +export interface IManageEmployee extends BaseEmployee{ + getSubordinates(flatOutput?: boolean): void; + + addSubordinate(person: BaseEmployee): void; + removeSubordinate(person: BaseEmployee): void; + subordinates: Map; } diff --git a/src/task_2/index.ts b/src/task_2/index.ts index f816934..4a33515 100644 --- a/src/task_2/index.ts +++ b/src/task_2/index.ts @@ -7,3 +7,82 @@ import { EmployeeDivision } from "../empoyee-separate.enum"; * Реализуйте необходимые методы. */ +export class Itworker extends BaseEmployee{ + constructor(fullName: string) { + super(fullName, EmployeeDivision.IT); + } + + public override getAuthority() { + console.log("программирую"); + } +} + +export class Calculus extends BaseEmployee{ + constructor(fullName: string) { + super(fullName, EmployeeDivision.calculus); + } + + public override getAuthority() { + console.log("считаю зарплату для Itworker"); + } +} + +export class Manager extends BaseEmployee implements IManageEmployee{ + constructor(fullName: string) { + super(fullName, EmployeeDivision.management); + } + + public override getAuthority() { + console.log("управляю работниками"); + } + + public subordinates: Map = new Map(); + + addSubordinate(person: BaseEmployee): void { + this.subordinates.get(person.getDepartment()).push(person); + } + + getSubordinates(flatOutput?: boolean): void { + if (flatOutput){ + console.log(this.subordinates.values()); + }else{ + console.log(this.subordinates.entries()); + } + } + + removeSubordinate(person: BaseEmployee): void { + const indexOfEmployee = this.subordinates.get(person.getDepartment()).indexOf(person); + this.subordinates.get(person.getDepartment()).splice(indexOfEmployee,1); + + } +} + +export class Administrator extends BaseEmployee implements IManageEmployee { + constructor(fullName: string) { + super(fullName, EmployeeDivision.administration); + } + + public override getAuthority() { + console.log("управляю управляющими"); + } + + public subordinates: Map = new Map(); + + addSubordinate(person: BaseEmployee): void { + this.subordinates.get(person.getDepartment()).push(person); + } + + getSubordinates(flatOutput?: boolean): void { + if (flatOutput) { + console.log(this.subordinates.values()); + } else { + console.log(this.subordinates.entries()); + } + } + + removeSubordinate(person: BaseEmployee): void { + const indexOfEmployee = this.subordinates.get(person.getDepartment()).indexOf(person); + this.subordinates.get(person.getDepartment()).splice(indexOfEmployee, 1); + + } +} \ No newline at end of file diff --git a/src/task_3/index.ts b/src/task_3/index.ts index 5dead10..0d2545c 100644 --- a/src/task_3/index.ts +++ b/src/task_3/index.ts @@ -6,5 +6,29 @@ * Материалы: * https://refactoring.guru/ru/design-patterns/factory-method * https://refactoring.guru/ru/design-patterns/abstract-factory -*/ + */ +import {BaseEmployee, IManageEmployee} from "../task_1"; +import {EmployeeDivision} from "../empoyee-separate.enum"; +import {Administrator, Calculus, Itworker, Manager} from "../task_2"; +export interface IEmployeeFactory { + makeManageWorker: (departure: EmployeeDivision.management | EmployeeDivision.administration, fullName: string) => IManageEmployee; + makeBaseWorker: (departure: EmployeeDivision.IT | EmployeeDivision.calculus, fullName: string) => BaseEmployee; +} +export class WorkerFactory implements IEmployeeFactory { + public makeManageWorker(departure: EmployeeDivision.management | EmployeeDivision.administration, fullName: string): IManageEmployee { + if (departure === EmployeeDivision.management) { + return new Manager(fullName); + } + + return new Administrator(fullName); + } + + public makeBaseWorker(departure: EmployeeDivision.IT | EmployeeDivision.calculus, fullName: string): BaseEmployee { + if (departure === EmployeeDivision.calculus) { + return new Calculus(fullName); + } + + return new Itworker(fullName); + } +} diff --git a/src/task_4/index.ts b/src/task_4/index.ts index 6abf009..9d8c0a0 100644 --- a/src/task_4/index.ts +++ b/src/task_4/index.ts @@ -7,4 +7,28 @@ * По сути это задание - песочница. * Вы можете конспектировать свои действия, для более глубокого понимания происходящего. */ +import {WorkerFactory} from "../task_3"; +import {EmployeeDivision} from "../empoyee-separate.enum"; +const jediCouncil = (factory: WorkerFactory) => { + const magisterJedi = factory.makeManageWorker(EmployeeDivision.administration, "Yoda"); + const jedi = []; + const padawans = []; + const younglings = []; + jedi[0] = factory.makeManageWorker(EmployeeDivision.management, "Obi-wan Kenobi"); + jedi[1] = factory.makeManageWorker(EmployeeDivision.management, "Anakin Skywalker"); + padawans[0] = factory.makeBaseWorker(EmployeeDivision.calculus, "Ahsoka Tano"); + padawans[1] = factory.makeBaseWorker(EmployeeDivision.calculus, "Luke Skywalker"); + younglings[0] = factory.makeBaseWorker(EmployeeDivision.IT, "Ashla"); + younglings[1] = factory.makeBaseWorker(EmployeeDivision.IT, "Katooni"); + magisterJedi.addSubordinate(jedi[0]); + magisterJedi.addSubordinate(jedi[1]); + jedi[0].addSubordinate(padawans[0]); + jedi[1].addSubordinate(padawans[1]); + jedi[0].addSubordinate(younglings[0]); + jedi[1].addSubordinate(younglings[1]); + magisterJedi.getSubordinates(); + jedi[1].getSubordinates(); +}; + +jediCouncil(new WorkerFactory()); \ No newline at end of file