composite code
This commit is contained in:
parent
9a6936ed7b
commit
41ff6962c3
|
@ -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();
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
module employee;
|
||||||
|
|
||||||
|
interface Employee
|
||||||
|
{
|
||||||
|
void showEmployDetails();
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue