DesignPattern/02.FactoryMethod/2.Code/main.cpp

23 lines
686 B
C++
Raw Normal View History

2019-10-17 23:32:47 +00:00
#include <iostream>
#include "FactoryMethod.h"
2021-08-30 12:13:41 +00:00
#include <memory>
2019-10-17 23:32:47 +00:00
int main()
{
2021-10-28 15:15:51 +00:00
printf("工厂方法模式\n");
2021-08-30 12:13:41 +00:00
2021-10-28 15:15:51 +00:00
// 定义工厂类对象和产品类对象
2021-08-30 12:13:41 +00:00
std::shared_ptr<AbstractFactory> fac = make_shared<BasketballFactory>();
std::shared_ptr<AbstractSportProduct> product = std::shared_ptr<AbstractSportProduct>(fac->getSportProduct());
2019-10-17 23:32:47 +00:00
2021-08-30 12:13:41 +00:00
fac = make_shared<FootballFactory>();
// product = std::shared_ptr<AbstractSportProduct>(fac->getSportProduct());
product = std::shared_ptr<AbstractSportProduct>(fac->getSportProduct());
fac = make_shared<VolleyballFactory>();
product = std::shared_ptr<AbstractSportProduct>(fac->getSportProduct());
2019-10-17 23:32:47 +00:00
system("pause");
return 0;
}