请帮我解决以下C ++设计问题
Class Office
{
std::list<Employees *> m_Employees;
string m_Address;
void AddEmployee(Employees *employee);
string GetAddress();
}
Class SalesOffice : public Office
{
int m_TotalEmployees_SalesPerYear;
int GetSalesPerYear();
}
Class FinanceOffice : public Office
{
int m_TotalEmployees_ProfitPerYear;
int GetProfitPerYear();
}
Class BookKeepingOffice : public Office
{
int m_TotalEmployees_RecordsPerYear;
int GetRecordsPerYear();
}
Class Employees
{
int id;
int GetID();
}
Class SalesEmployees : public Employees
{
int m_SalesPerYear;
int GetEmployeeSalesPerYear();
}
Class FinanceEmployees : public Employees
{
int m_ProfitPerYear;
int GetEmployeeProfitPerYear();
}
Class BookKeepingEmployees : public Employees
{
int m_RecordsPerYear;
int GetEmployeeRecordsPerYear();
}
Class Office有一个Class Employees列表。这种复合关系不能改变。 显然,任何类型的Office都只知道员工。 问题:SalesOffice的GetSalesPerYear如何访问GetEmployeeSalesPerYear() 注意:我不想在每个办公室里对员工进行强制分类。 有关设计和设计模式的任何建议吗?
答案 0 :(得分:0)
int GetEmployeeSalesPerYear();
应定义为Employee
的虚拟方法,返回0,SalesEmployees
应重新实现。