首页 > 代码库 > ChainOfResponsibility

ChainOfResponsibility

#include <iostream>using namespace std;class Chain{public:    bool Handle() { return false; }};class Level1 : public Chain{public:    bool Handle()    {        cout<<"Level1::true"<<endl;        return true;    }};class Level2 : public Level1{public:    bool Handle()    {        cout<<"Level2::Handle"<<endl;        return Level1::Handle();    }};class Level3 : public Level2{public:    bool Handle()    {        cout<<"Level3::Handle"<<endl;        return Level2::Handle();    }};int main(int argc, char *argv[]){    Level3 level3;    level3.Handle();    return 0;}

 

ChainOfResponsibility