#include <iostream>
using namespace std;
class AbstractPay
{
public :
virtual void pay()=0;
};
class CashPay: public AbstractPay
{
public :
void pay(){
//现金支付
cout<< "现金支付" <<endl;
}
};
class Creditcardpay: public AbstractPay
{
public :
void pay(){
//信用卡支付
cout<< "信用卡支付" <<endl;
}
};
class PayMethodFactory
{
public :
AbstractPay* getpayMethod(string type){
if((type .compare("cash"))==0){
return new CashPay;
} else /*if(type.compare("creditcard"))*/
{
return new Creditcardpay;
}
}
};
int main()
{
PayMethodFactory * factory=new PayMethodFactory ();
AbstractPay* a=factory->getpayMethod("cash");
a->pay();
AbstractPay* b=factory->getpayMethod("creditcard");
b->pay();
delete a;
delete b;
delete factory;
return 0;
}