composite code

This commit is contained in:
Alexander Zhirov 2022-11-18 01:06:11 +03:00
parent 9a6936ed7b
commit 41ff6962c3
5 changed files with 99 additions and 0 deletions

22
composite/composite/app.d Normal file
View File

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

View File

@ -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;
}
}

View File

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

View File

@ -0,0 +1,6 @@
module employee;
interface Employee
{
void showEmployDetails();
}

View File

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