Skip to content

Commit

Permalink
工厂方法模式
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseZ332623 committed Aug 20, 2024
1 parent 24285f2 commit 27ec07c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Factory_Design_Mode/factoryMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ struct Employee {
virtual ~Employee() {}
};

/**
* @brief 程序员类,继承自 Employee。
*/
struct Programer : public Employee
{
void show(void) const override {
Expand All @@ -57,6 +60,9 @@ struct Programer : public Employee
}
};

/**
* @brief 设计师类,继承自 Employee。
*/
struct Desinger : public Employee
{
void show(void) const override {
Expand Down Expand Up @@ -109,6 +115,9 @@ struct Department
virtual ~Department() {}
};

/**
* @brief IT 部门类,继承自 Department
*/
struct ITDepartment : public Department
{
Employee * createEmployee() const override {
Expand All @@ -117,6 +126,9 @@ struct ITDepartment : public Department
}
};

/**
* @brief UI 部门,继承自 Department
*/
struct UIDepartment : public Department
{
Employee * createEmployee() const override {
Expand Down Expand Up @@ -147,7 +159,7 @@ int main(int argc, char const *argv[])

#if ADDITIONAL
SecurityDepartment securityDepartment {};
Employee * guardA = securityDepartment.onboard();
Employee * guardA = securityDepartment.onboard();
delete guardA;
#endif

Expand Down

0 comments on commit 27ec07c

Please sign in to comment.