2019-11-03 23:46:24 +00:00
|
|
|
#ifndef __MEDIATOR_PATTERN_H__
|
|
|
|
#define __MEDIATOR_PATTERN_H__
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "Colleague.h"
|
|
|
|
|
2021-10-28 15:15:51 +00:00
|
|
|
// 抽象中介者
|
2019-11-03 23:46:24 +00:00
|
|
|
class Mediator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Mediator(){}
|
2021-04-04 13:09:08 +00:00
|
|
|
virtual ~Mediator(){}
|
2021-10-28 15:15:51 +00:00
|
|
|
// 声明抽象方法
|
2019-11-03 23:46:24 +00:00
|
|
|
virtual void operation(Colleague*) = 0;
|
2021-10-28 15:15:51 +00:00
|
|
|
// 声明注册方法
|
2019-11-03 23:46:24 +00:00
|
|
|
virtual void registerMethod(Colleague*) = 0;
|
|
|
|
};
|
|
|
|
|
2021-10-28 15:15:51 +00:00
|
|
|
// 具体中介者
|
2019-11-03 23:46:24 +00:00
|
|
|
class Agency:public Mediator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Agency(){}
|
|
|
|
void registerMethod(Colleague* person){
|
|
|
|
switch (person->getPersonType()){
|
|
|
|
case LANDLORD:
|
|
|
|
landlordList.push_back((Landlord*)person);
|
|
|
|
break;
|
|
|
|
case TENANT:
|
|
|
|
tenantList.push_back((Tenant*)person);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("wrong person\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void operation(Colleague* person){
|
|
|
|
switch (person->getPersonType()){
|
|
|
|
case LANDLORD:
|
|
|
|
for (int i = 0; i < tenantList.size(); i++){
|
|
|
|
tenantList[i]->answer();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TENANT:
|
|
|
|
for (int i = 0; i < landlordList.size(); i++){
|
|
|
|
landlordList[i]->answer();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
vector<Landlord*>landlordList;
|
|
|
|
vector<Tenant*>tenantList;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //__MEDIATOR_PATTERN_H__
|