DesignPattern/18.MediatorPattern/2.Code/Mediator.h

58 lines
1.0 KiB
C
Raw Normal View History

2019-11-03 23:46:24 +00:00
#ifndef __MEDIATOR_PATTERN_H__
#define __MEDIATOR_PATTERN_H__
#include "common.h"
#include "Colleague.h"
// <20><><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD>
class Mediator
{
public:
Mediator(){}
virtual ~Mediator(){}
2019-11-03 23:46:24 +00:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󷽷<EFBFBD>
virtual void operation(Colleague*) = 0;
// <20><><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><E1B7BD>
virtual void registerMethod(Colleague*) = 0;
};
// <20><><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD>
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__