DesignPattern/01.SimpleFactory/2.Code/main.cpp

25 lines
807 B
C++
Raw Normal View History

2019-10-17 13:55:01 +00:00
#include <iostream>
2021-08-30 12:13:41 +00:00
#include <memory>
2019-10-17 13:55:01 +00:00
#include "SimpleFactory.h"
int main()
{
2021-08-30 12:13:41 +00:00
printf("简单工厂模式\n");
2019-10-17 13:55:01 +00:00
2021-08-30 12:13:41 +00:00
//定义工厂类对象
std::shared_ptr<Factory> fac = std::make_shared<Factory>();
// std::shared_ptr<AbstractSportProduct> product = std::shared_ptr<AbstractSportProduct>(fac->getSportProduct("Basketball"));
std::shared_ptr<AbstractSportProduct> product = fac->getSportProduct("Basketball");
2021-08-30 12:13:41 +00:00
fac = std::make_shared<Factory>();
product = fac->getSportProduct("Football");
// product = std::shared_ptr<AbstractSportProduct>(fac->getSportProduct("Football"));
2019-10-17 13:55:01 +00:00
2021-08-30 12:13:41 +00:00
fac = std::make_shared<Factory>();
product = fac->getSportProduct("Volleyball");
// product = std::shared_ptr<AbstractSportProduct>(fac->getSportProduct("Volleyball"));
2021-08-30 12:13:41 +00:00
#ifdef win32
2019-10-17 13:55:01 +00:00
system("pause");
2021-08-30 12:13:41 +00:00
#endif
2019-10-17 13:55:01 +00:00
return 0;
}