1

请帮我解决以下 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();    
}

班级办公室有一份班级员工名单。这种复合关系不能改变。显然,任何类型的办公室都只知道员工。问题:SalesOffice 的 GetSalesPerYear 如何访问 GetEmployeeSalesPerYear() 注意:我不想对每个办公室的员工进行类型转换。关于设计和设计模式的任何建议?

4

1 回答 1

0

int GetEmployeeSalesPerYear();应该定义为 的虚方法Employee,返回 0 并且 SalesEmployees应该重新实现它。

于 2013-03-22T14:20:25.850 回答