2019-10-17 13:55:01 +00:00
|
|
|
|
#ifndef __SIMPLE_FACTORY__
|
|
|
|
|
#define __SIMPLE_FACTORY__
|
|
|
|
|
|
|
|
|
|
#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 13:55:01 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><F3B7BDB7><EFBFBD>
|
2021-04-04 13:09:08 +00:00
|
|
|
|
virtual void printName(){};
|
|
|
|
|
virtual void play(){};
|
2019-10-17 13:55:01 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Basketball
|
|
|
|
|
class Basketball :public AbstractSportProduct
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Basketball(){
|
|
|
|
|
printName();
|
|
|
|
|
play();
|
2021-04-04 13:09:08 +00:00
|
|
|
|
}
|
|
|
|
|
~Basketball()
|
|
|
|
|
{
|
|
|
|
|
|
2019-10-17 13:55:01 +00:00
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
void printName(){
|
|
|
|
|
printf("Jungle get Basketball\n");
|
|
|
|
|
}
|
|
|
|
|
void play(){
|
|
|
|
|
printf("Jungle play Basketball\n");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Football
|
|
|
|
|
class Football :public AbstractSportProduct
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Football(){
|
|
|
|
|
printName();
|
|
|
|
|
play();
|
2021-04-04 13:09:08 +00:00
|
|
|
|
}
|
|
|
|
|
~Football()
|
|
|
|
|
{
|
|
|
|
|
|
2019-10-17 13:55:01 +00:00
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
void printName(){
|
|
|
|
|
printf("Jungle get Football\n");
|
|
|
|
|
}
|
|
|
|
|
void play(){
|
|
|
|
|
printf("Jungle play Football\n");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Volleyball
|
|
|
|
|
class Volleyball :public AbstractSportProduct
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Volleyball(){
|
|
|
|
|
printName();
|
|
|
|
|
play();
|
2021-04-04 13:09:08 +00:00
|
|
|
|
}
|
|
|
|
|
~Volleyball()
|
|
|
|
|
{
|
|
|
|
|
|
2019-10-17 13:55:01 +00:00
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
void printName(){
|
|
|
|
|
printf("Jungle get Volleyball\n");
|
|
|
|
|
}
|
|
|
|
|
void play(){
|
|
|
|
|
printf("Jungle play Volleyball\n");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Factory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AbstractSportProduct *getSportProduct(string productName)
|
|
|
|
|
{
|
|
|
|
|
AbstractSportProduct *pro = NULL;
|
|
|
|
|
if (productName == "Basketball"){
|
|
|
|
|
pro = new Basketball();
|
|
|
|
|
}
|
|
|
|
|
else if (productName == "Football"){
|
|
|
|
|
pro = new Football();
|
|
|
|
|
}
|
|
|
|
|
else if (productName == "Volleyball"){
|
|
|
|
|
pro = new Volleyball();
|
|
|
|
|
}
|
|
|
|
|
return pro;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif //__SIMPLE_FACTORY__
|