From 41ff6962c3b22c479c3cc0cf94d723a63635cbf3 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 18 Nov 2022 01:06:11 +0300 Subject: [PATCH] composite code --- composite/composite/app.d | 22 ++++++++++++++++++++++ composite/composite/companydirectory.d | 23 +++++++++++++++++++++++ composite/composite/developer.d | 24 ++++++++++++++++++++++++ composite/composite/employee.d | 6 ++++++ composite/composite/manager.d | 24 ++++++++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 composite/composite/app.d create mode 100644 composite/composite/companydirectory.d create mode 100644 composite/composite/developer.d create mode 100644 composite/composite/employee.d create mode 100644 composite/composite/manager.d diff --git a/composite/composite/app.d b/composite/composite/app.d new file mode 100644 index 0000000..105f8e8 --- /dev/null +++ b/composite/composite/app.d @@ -0,0 +1,22 @@ +import companydirectory, developer, employee, manager; + +void main() +{ + auto dev1 = new Developer(100, "Lokesh Sharma", "Pro Developer"); + auto dev2 = new Developer(101, "Vinay Sharma", "Developer"); + auto engDirectory = new CompanyDirectory(); + engDirectory.addEmployee(dev1); + engDirectory.addEmployee(dev2); + + auto man1 = new Manager(200, "Kushagra Garg", "SEO Manager"); + auto man2 = new Manager(201, "Vikram Sharma ", "Kushagra's Manager"); + + auto accDirectory = new CompanyDirectory(); + accDirectory.addEmployee(man1); + accDirectory.addEmployee(man2); + + auto directory = new CompanyDirectory(); + directory.addEmployee(engDirectory); + directory.addEmployee(accDirectory); + directory.showEmployDetails(); +} diff --git a/composite/composite/companydirectory.d b/composite/composite/companydirectory.d new file mode 100644 index 0000000..7e9ee86 --- /dev/null +++ b/composite/composite/companydirectory.d @@ -0,0 +1,23 @@ +module companydirectory; + +import employee, developer, manager; +import std.stdio : writeln; +import std.algorithm : remove; + +class CompanyDirectory : Employee +{ + private Employee[] employee; + + override void showEmployDetails() + { + foreach (Employee val; employee) + { + val.showEmployDetails(); + } + } + + void addEmployee(Employee employee) + { + this.employee ~= employee; + } +} diff --git a/composite/composite/developer.d b/composite/composite/developer.d new file mode 100644 index 0000000..da292b3 --- /dev/null +++ b/composite/composite/developer.d @@ -0,0 +1,24 @@ +module developer; + +import employee; +import std.stdio : writeln; + +class Developer : Employee +{ +private: + string name; + int empId; + string position; +public: + this(int empId, string name, string position) + { + this.empId = empId; + this.name = name; + this.position = position; + } + + override void showEmployDetails() + { + writeln(empId, " ", name, " ", position); + } +} diff --git a/composite/composite/employee.d b/composite/composite/employee.d new file mode 100644 index 0000000..b46275d --- /dev/null +++ b/composite/composite/employee.d @@ -0,0 +1,6 @@ +module employee; + +interface Employee +{ + void showEmployDetails(); +} diff --git a/composite/composite/manager.d b/composite/composite/manager.d new file mode 100644 index 0000000..fce4c47 --- /dev/null +++ b/composite/composite/manager.d @@ -0,0 +1,24 @@ +module manager; + +import employee; +import std.stdio : writeln; + +class Manager : Employee +{ +private: + string name; + int empId; + string position; +public: + this(int empId, string name, string position) + { + this.empId = empId; + this.name = name; + this.position = position; + } + + override void showEmployDetails() + { + writeln(empId, " ", name, " ", position); + } +}