裘千尺裘千仞裘千丈与杨过篇--责任链模式C++实现

学了C++基本的语法都知道继承可以让子类拥有更多的功能,除了继承还有组合,委托,也能让一个类的功能增加。设计模式,这个设计是设计继承,组合,委托,之间相互叠加的方式,让其符合业务需求。

责任链模式是继承 +
委托的运用。在以下代码中,定义一个抽象管理者类,派生经理类,总监类,总经理类。有些决定经理可以做,如果经理不能做,那么调用其委托的总监来做,若总监也不能做,则调用其委托的总经理来做。

这些代码都是在学习这些的过程中码的。。。。。

上一篇:武侠小说之令狐冲篇–适配器模式C++
下一篇:黄药师及其五大弟子功夫继承关系篇----命令模式C++实现
上代码,亲测有效!

Exe : Chain.o
	g++ -o Exe Chain.o
main.o : Chain.cpp
	g++ -c -g Chain.cpp
clean :
	rm Chain
#include <iostream>
#include <string>
using namespace std;


//责任链模式

class Abstract_Manage
{
public:
    virtual void deal_with(string worker_name, int money) = 0;
    Abstract_Manage* p_Abstract_Manage = NULL;
    string Manage_Name;
};

class Km : public Abstract_Manage
{
public:

Km(Abstract_Manage* p_Abstract_Manage, string Manage_Name);
 void deal_with(string worker_name, int money);
};
Km::Km(Abstract_Manage* p_Abstract_Manage, string this_Manage_Name)
{
    this->p_Abstract_Manage = p_Abstract_Manage;
    this->Manage_Name = this_Manage_Name;
}

void Km::deal_with(string worker_name, int money)
{
    if(money < 10000)
    {
        cout << this->Manage_Name << "同意" << worker_name << "加薪" << money << "元" << endl;
    }
    else
    {
        cout << "Let me tell you a story !" << endl;
        
    }
}

class M : public Abstract_Manage
{
public:
    M(Abstract_Manage* p_Abstract_Manage, string Manage_Name);
 void deal_with(string worker_name, int money);
};
M::M(Abstract_Manage* p_Abstract_Manage, string this_Manage_Name)
{
    this->p_Abstract_Manage = p_Abstract_Manage;
    this->Manage_Name = this_Manage_Name;
}

void M::deal_with(string worker_name, int money)
{
    if(money < 5000)
    {
        cout << this->Manage_Name << "同意" << worker_name << "加薪" << money << "元" << endl;
    }
    else
    {
        p_Abstract_Manage->deal_with(worker_name, money);
    }
}

class Dm : public Abstract_Manage
{
public:
    Dm(Abstract_Manage* p_Abstract_Manage, string Manage_Name);
 void deal_with(string worker_name, int money);
};
Dm::Dm(Abstract_Manage* p_Abstract_Manage, string this_Manage_Name)
{
    this->p_Abstract_Manage = p_Abstract_Manage;
    this->Manage_Name = this_Manage_Name;
}

void Dm::deal_with(string worker_name, int money)
{
    if(money < 2000)
    {
        cout << this->Manage_Name << "同意" << worker_name << "加薪" << money << "元" << endl;
    }
    else
    {
        p_Abstract_Manage->deal_with(worker_name, money);
    }
}

int main(void)
{
    Km* p_Km = new Km( NULL, "裘千尺");
    M* p_M = new M(p_Km, "裘千仞");
    Dm* p_Dm = new Dm(p_M, "裘千丈");
    p_Dm->deal_with("杨过", 60000);

    delete p_Dm;
    delete p_M;
    delete p_Km;
    



    return 0;
}

哎呦喂ヾ(✿゚▽゚)ノ~路长馆小,雪轻帘薄,酒热乎,这位爷~您ヾ(✿゚▽゚)ノ~ 里面坐~
本公众号专注分享C++,ffmpeg,opencv等相关音视频知识
webrtc,udp,tcp,rtsp,rtmp,srt/nginx+rtmp等流媒体协议和服务器
同时也会有大厂音视频技术专家不定期直播分享…
国人开发流媒体srs服务器,及yangrtc(国人版的webrtc)协议新动向
偶尔分享下程序员梦呓碎碎念(๑•॒̀ ູ॒•́๑)啦啦啦
目前刚刚开通,接受读者的优质投稿…
鉴于国内音视频圈子小,起步晚,以致分享少,门槛高,特开通分享,一起扇动这阵风吧!
微信扫描下方二维码,关注公众号,赶快进入音视频开发者社区吧!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

、、、、南山小雨、、、、

分享对你有帮助,打赏一下吧!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值