initialize repository of design pattern template

This commit is contained in:
LU
2025-08-09 08:41:14 +08:00
commit 1727e31b9d
32 changed files with 2149 additions and 0 deletions
+96
View File
@@ -0,0 +1,96 @@
#include "chain_of_responsibility.hpp"
int PersonA::getDayoff()
{
return m_Dayoff;
}
string PersonA::getName()
{
return m_Name;
}
string PersonA::getReason()
{
return m_Reason;
}
void PersonA::setLeader(Manager* pLeader)
{
m_pLeader = pLeader;
}
void PersonA::Request()
{
cout << m_Name << "申请请假" << m_Dayoff << "天,请假事由:" << m_Reason << endl;
if (m_pLeader != nullptr)
{
m_pLeader->handleRequest(this);
}
}
string Manager::getName()
{
return m_Name;
}
string Manager::getTitle()
{
return m_Title;
}
void Manager::setNextHander(Manager* p_NextHandler)
{
m_pNextHandle = p_NextHandler;
}
void Supervisor::handleRequest(PersonA* pPerson)
{
if (pPerson->getDayoff() <= 2)
{
cout << "同意" << pPerson->getName() << "请假,签字人:" << getName() << "(" << getTitle() << ")" << endl;
}
if (m_pNextHandle != nullptr)
{
m_pNextHandle->handleRequest(pPerson);
}
}
void DepartmentManager::handleRequest(PersonA* pPerson)
{
if (pPerson->getDayoff() <= 5 && pPerson->getDayoff() > 2)
{
cout << "同意" << pPerson->getName() << "请假,签字人:" << getName() << "(" << getTitle() << ")" << endl;
}
if (m_pNextHandle != nullptr)
{
m_pNextHandle->handleRequest(pPerson);
}
}
void CEO::handleRequest(PersonA* pPerson)
{
if (pPerson->getDayoff() > 5)
{
cout << "同意" << pPerson->getName() << "请假,签字人:" << getName() << "(" << getTitle() << ")" << endl;
}
if (m_pNextHandle != nullptr)
{
m_pNextHandle->handleRequest(pPerson);
}
}
void Administrator::handleRequest(PersonA* pPerson)
{
cout << pPerson->getName() << "的请假申请已审核,情况属实!已备案处理。处理人:"
<< getName() << "(" << getTitle() << ")" << endl;
cout << endl;
if (m_pNextHandle != nullptr)
{
m_pNextHandle->handleRequest(pPerson);
}
}