每日总结

软件设计模式  职责链模式:

 

#include <iostream>
#include <string>
using namespace std;
class CGD {
public:
    int money;
    CGD() {};
    CGD(int money) { this->money = money; };
    int getMoney() { return money; };
    void setMoney(int money) { this->money = money; };
};
class Leader {
public:
    string name;
    Leader* up;
    Leader() {};
    Leader(string name);
    void setUp(Leader* up) { this->up = up; };
    virtual void handleCGD(CGD* cgd) = 0;
};
class ZR :public Leader {
public:
    ZR(string name) { this->name = name; };
    void handleCGD(CGD* cgd) {
        if (cgd->getMoney() < 10000) {
            cout << "主任" << name << "审批了" << cgd->getMoney() << "元的采购单" << endl;
        }
        else {
            this->up->handleCGD(cgd);
        }
    };

};
class BMJL :public Leader {
public:
    BMJL(string name) { this->name = name; };
    void handleCGD(CGD* cgd) {
        if (cgd->getMoney() < 50000) {
            cout << "部门经理" << name << "审批了" << cgd->getMoney() << "元的采购单" << endl;
        }
        else {
            this->up->handleCGD(cgd);
        }
    };
};
class FZJL :public Leader {
public:
    FZJL(string name) { this->name = name; };
    void handleCGD(CGD* cgd) {
        if (cgd->getMoney() < 100000) {
            cout << "副总经理" << name << "审批了" << cgd->getMoney() << "元的采购单" << endl;
        }
        else {
            this->up->handleCGD(cgd);
        }
    };
};
class ZJL :public Leader {
public:
    ZJL(string name) { this->name = name; };
    void handleCGD(CGD* cgd) {
        if (cgd->getMoney() < 200000) {
            cout << "总经理" << name << "审批了" << cgd->getMoney() << "元的采购单" << endl;
        }
        else {
            cout << cgd->getMoney() << "元的采购单需要开职工大会来决定" << endl;
        }
    };
};
int main() {
    Leader* zr, * bmjl, * fzjl, * zjl;

    zr = new ZR("老王");
    bmjl = new BMJL("老李");
    fzjl = new FZJL("老张");
    zjl = new ZJL("老赵");

    zr->setUp(bmjl);
    bmjl->setUp(fzjl);
    fzjl->setUp(zjl);

    zr->handleCGD(new CGD(100));
    zr->handleCGD(new CGD(1000));
    zr->handleCGD(new CGD(11000));
    zr->handleCGD(new CGD(60000));
    zr->handleCGD(new CGD(110000));
    zr->handleCGD(new CGD(190000));
    zr->handleCGD(new CGD(250000));
    return 0;
}

 

posted @   chenghaixinag  阅读(21)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示