samedi 21 décembre 2019

What class design will be change in case of promotion of roles in employee class hierarchy

I am building the simple object-oriented inheritance class for the employee management system, but I found one issue if some employee gets promotions then how we can handle such scenario.

/* This code represents the employee class hierarchy using inheritance relation */

#include <iostream>

using namespace std;
/* This is Employee Class */
class Employee
{

private:
    string empname;
    int empid;
    float salary;
public:
    int getSalary();

};
/* This is Manager Class  Derived from Employee */
class Manager: public Employee
{
       public:
            int getSalary(); // This will return salary of manager
};
/* This is Clerk Class  Derived from Employee */
class Clerk: public Employee
{
public:
    int getSalary(); // This will return salary of clerk
};
/* This is Accountant Class Derived from Employee */
class Accountant : public Employee
{
public:
    int getSalary(); // This will return salary of Accountant
};
/* This is Accountant Class Derived from Employee */
class Developer: public Employee
{
public:
    int getSalary(); // This will return salary of Developer
};
// Now if some employee gets a promotion or demotion how to handle such scenario
// Suppose someday Developer becomes Manager then how to manage those changes in c++ classes

Aucun commentaire:

Enregistrer un commentaire