#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//类的单一性原则
//改进
class AbstractWorker
{
public:
virtual void doBusiness() = 0;
};
//专门办理存款业务的
class SaveBankerWorker : public AbstractWorker
{
public:
virtual void doBusiness()
{
cout << "办理存款业务..." << endl;
}
};
//专门办理付款业务的
class payServiceWorker : public AbstractWorker
{
public:
virtual void doBusiness()
{
cout << "办理支付业务..." << endl;
}
};
//专门办理转账业务的
class tranferServiceWorker : public AbstractWorker
{
public:
virtual void doBusiness()
{
cout << "办理转账业务..." << endl;
}
};
//中层业务
void doNewBusiness(AbstractWorker* work)
{
work->doBusiness();
delete(work);
work = NULL;
}
void test03()
{
doNewBusiness(new tranferServiceWorker);
doNewBusiness(new payServiceWorker);
}
int main()
{
test03();
system("pause");
return 0;
}
让函数尽量依赖抽象层。。。。。。