2019-10-19 01:32:12 +00:00
|
|
|
|
#ifndef __ABSTRACT_FACTORY__
|
|
|
|
|
#define __ABSTRACT_FACTORY__
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>AbstractBall
|
|
|
|
|
class AbstractBall
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AbstractBall(){
|
|
|
|
|
|
|
|
|
|
}
|
2021-04-04 13:09:08 +00:00
|
|
|
|
virtual ~AbstractBall(){}
|
2019-10-19 01:32:12 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><F3B7BDB7><EFBFBD>
|
2021-04-04 13:09:08 +00:00
|
|
|
|
virtual void play(){};
|
2019-10-19 01:32:12 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Basketball
|
|
|
|
|
class Basketball :public AbstractBall
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Basketball(){
|
|
|
|
|
play();
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
void play(){
|
|
|
|
|
printf("Jungle play Basketball\n\n");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>Football
|
|
|
|
|
class Football :public AbstractBall
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Football(){
|
|
|
|
|
play();
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
void play(){
|
|
|
|
|
printf("Jungle play Football\n\n");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>AbstractShirt
|
|
|
|
|
class AbstractShirt
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AbstractShirt(){}
|
2021-04-04 13:09:08 +00:00
|
|
|
|
virtual ~AbstractShirt(){}
|
2019-10-19 01:32:12 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><F3B7BDB7><EFBFBD>
|
2021-04-04 13:09:08 +00:00
|
|
|
|
virtual void wearShirt(){};
|
2019-10-19 01:32:12 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>BasketballShirt
|
|
|
|
|
class BasketballShirt :public AbstractShirt
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
BasketballShirt(){
|
|
|
|
|
wearShirt();
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
void wearShirt(){
|
|
|
|
|
printf("Jungle wear Basketball Shirt\n\n");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7>FootballShirt
|
|
|
|
|
class FootballShirt :public AbstractShirt
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FootballShirt(){
|
|
|
|
|
wearShirt();
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
void wearShirt(){
|
|
|
|
|
printf("Jungle wear Football Shirt\n\n");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><F3B9A4B3><EFBFBD>
|
|
|
|
|
class AbstractFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-04-04 13:09:08 +00:00
|
|
|
|
virtual ~AbstractFactory() {}
|
2019-10-19 01:32:12 +00:00
|
|
|
|
virtual AbstractBall *getBall() = 0;
|
|
|
|
|
virtual AbstractShirt *getShirt() = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>幤<EFBFBD><E5B9A4><EFBFBD><EFBFBD>BasketballFactory
|
|
|
|
|
class BasketballFactory :public AbstractFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
BasketballFactory(){
|
|
|
|
|
printf("BasketballFactory\n");
|
|
|
|
|
}
|
|
|
|
|
AbstractBall *getBall(){
|
|
|
|
|
printf("Jungle get basketball\n");
|
|
|
|
|
return new Basketball();
|
|
|
|
|
}
|
|
|
|
|
AbstractShirt *getShirt(){
|
|
|
|
|
printf("Jungle get basketball shirt\n");
|
|
|
|
|
return new BasketballShirt();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>幤<EFBFBD><E5B9A4><EFBFBD><EFBFBD>BasketballFactory
|
|
|
|
|
class FootballFactory :public AbstractFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FootballFactory(){
|
|
|
|
|
printf("FootballFactory\n");
|
|
|
|
|
}
|
|
|
|
|
AbstractBall *getBall(){
|
|
|
|
|
printf("Jungle get football\n");
|
|
|
|
|
return new Football();
|
|
|
|
|
}
|
|
|
|
|
AbstractShirt *getShirt(){
|
|
|
|
|
printf("Jungle get football shirt\n");
|
|
|
|
|
return new FootballShirt();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif //__ABSTRACT_FACTORY__
|