Skip to content

Commit

Permalink
静态 “创建方法”
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseZ332623 committed Aug 19, 2024
1 parent 3ece784 commit 1e64fe2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Binary file not shown.
44 changes: 44 additions & 0 deletions src/Factory_Design_Mode/staticCreatMethod.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <MyLib/myLogerDef.h>

using namespace MyLib::MyLoger;

/**
* @brief 工厂模式学习前置任务之:静态创建方法:
* 需求:假设需要设计一个员工管理系统,
* 目前是创业初期,部门内只有程序员一个职位,
* 使用静态创建方法对该需求进行建模。
*/

/**
* @brief 程序员类
*/
struct Programer
{
Programer(void) {
CORRECT_LOG("Create a porgramer object complete.\n");
}
};

/**
* @brief 部门类,负责各个职员类的创建
*/
struct Department
{
/**
* @brief Create a Programer object。
*/
static Programer * createProgramer(void)
{
NOTIFY_LOG("Department class create a porgramer object.\n");
return new Programer();
}
};

int main(int argc, char const *argv[])
{
Programer * newProgamer = Department::createProgramer();

delete newProgamer;

return EXIT_SUCCESS;
}

0 comments on commit 1e64fe2

Please sign in to comment.