DesignPattern/05.PrototypePattern/2.Code/main.cpp

56 lines
1.6 KiB
C++
Raw Normal View History

2019-10-20 03:06:41 +00:00
#include "PrototypePattern.h"
int main()
{
#if 0
ConcreteWork *singleWork = new ConcreteWork("Single",1001,"Single_Model");
2021-10-28 15:15:51 +00:00
printf("\nSingle的作业\n");
2019-10-20 03:06:41 +00:00
singleWork->printWorkInfo();
2021-10-28 15:15:51 +00:00
printf("\njungle直接抄作业……\n");
2019-10-20 03:06:41 +00:00
ConcreteWork *jungleWork = singleWork;
2021-10-28 15:15:51 +00:00
printf("\nJungle的作业\n");
2019-10-20 03:06:41 +00:00
jungleWork->printWorkInfo();
2021-10-28 15:15:51 +00:00
// 抄完改名字和学号,否则会被老师查出来
printf("\njungle抄完改名字和学号否则会被老师查出来……\n");
2019-10-20 03:06:41 +00:00
jungleWork->setName("jungle");
jungleWork->setIdNum(1002);
WorkModel *jungleModel = new WorkModel();
jungleModel->setWorkModelName("Jungle_Model");
jungleWork->setModel(jungleModel);
2021-10-28 15:15:51 +00:00
// 检查下是否改对了
printf("\nSingle的作业\n");
2019-10-20 03:06:41 +00:00
singleWork->printWorkInfo();
2021-10-28 15:15:51 +00:00
printf("\nJungle的作业\n");
2019-10-20 03:06:41 +00:00
jungleWork->printWorkInfo();
#endif
ConcreteWork *singleWork = new ConcreteWork("Single", 1001, "Single_Model");
2021-10-28 15:15:51 +00:00
printf("\nSingle的作业\n");
2019-10-20 03:06:41 +00:00
ConcreteWork *jungleWork = singleWork->clone();
2021-10-28 15:15:51 +00:00
printf("\njungle直接抄作业……\n");
2019-10-20 03:06:41 +00:00
2021-10-28 15:15:51 +00:00
// 抄完改名字和学号,否则会被老师查出来
printf("\njungle抄完改名字和学号否则会被老师查出来……\n");
2019-10-20 03:06:41 +00:00
jungleWork->setName("jungle");
jungleWork->setIdNum(1002);
WorkModel *jungleModel = new WorkModel();
jungleModel->setWorkModelName("Jungle_Model");
jungleWork->setModel(jungleModel);
2021-10-28 15:15:51 +00:00
// 检查下是否改对了
printf("\nSingle的作业\n");
2019-10-20 03:06:41 +00:00
singleWork->printWorkInfo();
2021-10-28 15:15:51 +00:00
printf("\nJungle的作业\n");
2019-10-20 03:06:41 +00:00
jungleWork->printWorkInfo();
system("pause");
2020-11-29 07:28:46 +00:00
delete singleWork;
delete jungleModel;
delete jungleWork;
2019-10-20 03:06:41 +00:00
return 0;
}