Mediator

#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
class g
{
public:
  virtual ~g(){cout<<"g 基类析构"<<endl;}
  virtual string Say(string str) = 0;
  virtual void Listen(string str) = 0;
};
class wch:public g
{
public:
  virtual ~wch(){cout<<"wch 子类析构"<<endl;}
  virtual string Say(string str){
    return str;
  }
  virtual void Listen(string str){
    cout<<"I heard tzh said:"<<str<<".I am very happy!"<<endl;
  }
};
class tzh:public g
{
public:
  virtual ~tzh(){cout<<"tzh 子类析构"<<endl;}
  virtual string Say(string str){
    return str;
  }
  virtual void Listen(string str){
    cout<<"I heard wch said:"<<str<<".I am very happy!"<<endl;
  }
};
class Mediator
{
public:
  virtual ~Mediator(){cout<<"Mediator 基类析构"<<endl;}
  virtual void wchSayTotzh(string str) = 0;
  virtual void tzhSayTowch(string str) = 0;
};
class gMediator:public Mediator
{
  g* pWch;
  g* pTzh;
public:
  virtual ~gMediator(){
    cout<<"gMediator 子类析构"<<endl;
    delete pWch;
    delete pTzh;
  }
  gMediator(){
    pWch = new wch;
    pTzh = new tzh;
  }
  void wchSayTotzh(string str){
    pTzh->Listen(pWch->Say(str) + ":sister");
  }
  void tzhSayTowch(string str){
    pWch->Listen(pTzh->Say(str) + ":sister");
  }
};
void Do(Mediator* pM)
{
  pM->wchSayTotzh(string("let's wash together?"));
  pM->tzhSayTowch(string("wawo ok"));
  delete pM;
}
int main(int argc, char *argv[])
{
    Do(new gMediator);
    system("PAUSE");
    return EXIT_SUCCESS;
}

你可能感兴趣的:(String,delete,System,Class,include)