2019-10-17 23:32:47 +00:00
|
|
|
|
#ifndef __FACTORY_METHOD__
|
|
|
|
|
#define __FACTORY_METHOD__
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>AbstractProduct
|
|
|
|
|
class AbstractSportProduct
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AbstractSportProduct(){
|
|
|
|
|
|
|
|
|
|
}
|
2021-04-04 13:09:08 +00:00
|
|
|
|
virtual ~AbstractSportProduct(){}
|
2019-10-17 23:32:47 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><F3B7BDB7><EFBFBD>
|
2021-04-04 13:09:08 +00:00
|
|
|
|
virtual void printName(){};
|
|
|
|
|
virtual void play(){};
|
2019-10-17 23:32:47 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Basketball
|
|
|
|
|
class Basketball :public AbstractSportProduct
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Basketball(){
|
|
|
|
|
printName();
|
|
|
|
|
play();
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
void printName(){
|
|
|
|
|
printf("Jungle get Basketball\n");
|
|
|
|
|
}
|
|
|
|
|
void play(){
|
|
|
|
|
printf("Jungle play Basketball\n\n");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Football
|
|
|
|
|
class Football :public AbstractSportProduct
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Football(){
|
|
|
|
|
printName();
|
|
|
|
|
play();
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
void printName(){
|
|
|
|
|
printf("Jungle get Football\n");
|
|
|
|
|
}
|
|
|
|
|
void play(){
|
|
|
|
|
printf("Jungle play Football\n\n");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Volleyball
|
|
|
|
|
class Volleyball :public AbstractSportProduct
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Volleyball(){
|
|
|
|
|
printName();
|
|
|
|
|
play();
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
void printName(){
|
|
|
|
|
printf("Jungle get Volleyball\n");
|
|
|
|
|
}
|
|
|
|
|
void play(){
|
|
|
|
|
printf("Jungle play Volleyball\n\n");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><F3B9A4B3><EFBFBD>
|
|
|
|
|
class AbstractFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-04-04 13:09:08 +00:00
|
|
|
|
virtual ~AbstractFactory(){}
|
2019-10-17 23:32:47 +00:00
|
|
|
|
virtual AbstractSportProduct *getSportProduct() = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>幤<EFBFBD><E5B9A4><EFBFBD><EFBFBD>BasketballFactory
|
|
|
|
|
class BasketballFactory :public AbstractFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
BasketballFactory(){
|
|
|
|
|
printf("BasketballFactory\n");
|
|
|
|
|
}
|
|
|
|
|
AbstractSportProduct *getSportProduct(){
|
|
|
|
|
printf("basketball");
|
|
|
|
|
return new Basketball();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>幤<EFBFBD><E5B9A4><EFBFBD><EFBFBD>FootballFactory
|
|
|
|
|
class FootballFactory :public AbstractFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FootballFactory(){
|
|
|
|
|
printf("FootballFactory\n");
|
|
|
|
|
}
|
|
|
|
|
AbstractSportProduct *getSportProduct(){
|
|
|
|
|
return new Football();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>幤<EFBFBD><E5B9A4><EFBFBD><EFBFBD>VolleyballFactory
|
|
|
|
|
class VolleyballFactory :public AbstractFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
VolleyballFactory(){
|
|
|
|
|
printf("VolleyballFactory\n");
|
|
|
|
|
}
|
|
|
|
|
AbstractSportProduct *getSportProduct(){
|
|
|
|
|
return new Volleyball();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif //__FACTORY_METHOD__
|