Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design data structure for Employee-Manager

Tags:

java

c++

c#

The question is to design a structure for the employee/manager system.

1) An employee belongs to a manager.

2) A manager has several employees.

3) Manager may also belong to a manager.

4) Employee has only one manager

Design the data structure so that it supports the following operation: delete an employee/manager, promotion(an employee becomes a manager).

Any programming language would suffice.

Note: I do not want code. Just the verbal explanation would be ok.

like image 772
Ian McGrath Avatar asked Jan 28 '26 19:01

Ian McGrath


1 Answers

My first idea is to use employee as baseclass with a property manager as pointer to the manager-object (and other necessary properties like 'id') and a class manager, inheriting from employee with a list of pointers to employees.

This could be wrapped in a model containing a list of all employees/manager and methods like 'promote (employee)'. Employee could have also a method like 'promote', which returns a manager-object. The manager-class could have a constructor with employee-parameter...

Update (C# code):

public class Employee
{

    public string ID;
    public Manager Manager;

    public Manager promote() { return new Manager(this); }

    public Employee() { }

}

public class Manager : Employee
{

    public List<Employee> Employees;

    public Manager() { }
    public Manager(Employee employee) {...}

}

public class EmployeeModel
{

    private List<Employee> employees;
    public List<Employee> Employees { get { return this.employees; } }

    public void addEmployee(...) {...}
    public void removeEmployee(...) {...}
    public void promoteEmployee(...) {...}

}

Somehow like this...

like image 179
Martin Tausch Avatar answered Jan 31 '26 08:01

Martin Tausch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!