蝸牛的家
男兒當自強
C++博客
首頁
新文章
新隨筆
聚合
管理
posts - 48, comments - 21, trackbacks - 0
C++設計模式-ChainOfResponsibility
意圖:
使多個對象都有機會處理請求,從而避免請求的發送者和接收者之間的耦合關系,將這些對象連成一條鏈,并沿著這條鏈傳遞請求,直到有一個對象處理它為止
UML圖:
適用:
有多個的對象可以處理一個請求,哪個對象處理該請求運行時刻自動確定
你想在不明確指定接收者的情況下,向多個對象匯總的一個提交請求
可處理一個請求的對象結合應被動態指定
//test.h
//////////////////////////////////////////////////////////////////////////
class Handler
{
public:
Handler(Handler *pSuccessor = NULL);
virtual ~Handler();
virtual void HandlerRequest() = 0;
protected:
Handler* m_pSuccessor;
};
class ConCreateHandle1 : public Handler
{
public:
ConCreateHandle1(Handler *pSuccessor = NULL) : Handler(pSuccessor){}
virtual ~ConCreateHandle1(){}
virtual void HandlerRequest();
};
class ConCreateHandle2 : public Handler
{
public:
ConCreateHandle2(Handler *pSuccessor = NULL) : Handler(pSuccessor){}
virtual ~ConCreateHandle2(){}
virtual void HandlerRequest();
};
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
<
iostream
>
#include "test.h"
using namespace std;
//////////////////////////////////////////////////////////////////////////
Handler::Handler(Handler *pSuccessor /* = NULL */) : m_pSuccessor(pSuccessor)
{
}
Handler::~Handler()
{
delete m_pSuccessor;
m_pSuccessor = NULL;
}
void ConCreateHandle1::HandlerRequest()
{
if (NULL != m_pSuccessor)
{
m_pSuccessor->HandlerRequest();
}
else
{
cout
<
< "HandlerRequest
by ConCreateHandle1\n";
}
}
void ConCreateHandle2::HandlerRequest()
{
// 如果m_pSuccessor被初始化了就調用他的接口,負責調用自己的接口
if (NULL !
= m_pSuccessor)
{
m_pSuccessor-
>
HandlerRequest();
}
else
{
cout
<
< "HandlerRequest
by ConCreateHandle2\n";
}
}
//////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
Handler *p1
= new
ConCreateHandle1;
Handler *p2
= new
ConCreateHandle2(p1);
p2-
>
HandlerRequest();
delete p2;
system("pause");
return 0;
}
posted on 2008-08-19 23:27
黑色天使
閱讀(327)
評論(0)
編輯
收藏
引用
所屬分類:
設計模式
只有注冊用戶
登錄
后才能發表評論。
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
相關文章:
decorator模式
MVC模式理解——當年給我一個browser多好(轉)
C++設計模式-趣解
C++設計模式-visitor
C++設計模式-Memento
C++模式-Iterator
C++設計模式-Observer
C++設計模式-Command
C++模式-FlyWeight
C++設計模式-ChainOfResponsibility
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
<
2008年12月
>
日
一
二
三
四
五
六
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆分類
C\C++(8)
Hacker(1)
STL
VC&MFC(4)
操作系統(1)
多進程&多線程
流媒體開發
內存管理技術(2)
軟件工程(1)
設計模式(20)
數據結構&算法(2)
網絡開發(3)
隨筆檔案
2011年4月 (1)
2011年3月 (2)
2009年7月 (1)
2009年6月 (2)
2009年3月 (1)
2009年2月 (3)
2009年1月 (3)
2008年12月 (5)
2008年11月 (1)
2008年10月 (3)
2008年9月 (3)
2008年8月 (23)
文章檔案
2011年3月 (1)
2009年6月 (1)
2008年11月 (1)
搜索
最新評論
1.?re: C++設計模式-Observer
評論內容較長,點擊標題查看
--no7dw
2.?re: YUV格式詳細解釋與FFMPEG的關系
評論內容較長,點擊標題查看
--windsome
3.?re: 鍵盤過濾驅動源代碼
@soul
再怎么懶也應該自己實現一部分吧
--黑色天使
4.?re: 鍵盤過濾驅動源代碼[未登錄]
再怎么懶也該加上unload例程吧
--soul
5.?re: CHttpDownLoad Beta 1.0
評論內容較長,點擊標題查看
--tangxinfa
閱讀排行榜
1.?RGB、YUY2、YUYV、YVYU、UYVY與AYUV(轉)(6703)
2.?YUV格式詳細解釋與FFMPEG的關系(4320)
3.?如何檢測內存泄漏(轉)(3908)
4.?memcpy的BUG(2731)
5.?內存池技術學習筆記(2361)
評論排行榜
1.?CHttpDownLoad Beta 1.0(10)
2.?memcpy的BUG(5)
3.?事件模型SOCKET封裝(2)
4.?鍵盤過濾驅動源代碼(2)
5.?C++設計模式-Observer(1)
Copyright ©2025 黑色天使 Powered By
博客園
模板提供:
滬江博客
怡红院日本一道日本久久
|
久久人人爽人人爽人人片av麻烦
|
久久精品国产99久久丝袜
|
欧美久久亚洲精品
|
亚洲日韩中文无码久久
|
青青草国产精品久久
|
性欧美大战久久久久久久
|
中文字幕久久精品无码
|
国内精品久久久久
|
色婷婷狠狠久久综合五月
|
久久精品毛片免费观看
|
久久涩综合
|
好属妞这里只有精品久久
|
久久婷婷色综合一区二区
|
国产99久久久国产精免费
|
99蜜桃臀久久久欧美精品网站
|
久久综合九色综合久99
|
久久妇女高潮几次MBA
|
亚洲国产精品狼友中文久久久
|
精品久久777
|
99蜜桃臀久久久欧美精品网站
|
久久人人超碰精品CAOPOREN
|
91精品国产9l久久久久
|
人妻无码精品久久亚瑟影视
|
久久国产V一级毛多内射
|
国产欧美久久一区二区
|
国产精品久久99
|
潮喷大喷水系列无码久久精品
|
久久久精品人妻一区二区三区蜜桃
|
久久久久国产一区二区
|
久久精品国产精品亚洲人人
|
青青青青久久精品国产h
|
97久久久精品综合88久久
|
伊人久久大香线焦AV综合影院
|
亚洲国产精品婷婷久久
|
久久精品国产精品亚洲毛片
|
狠狠色丁香久久婷婷综合
|
亚洲色婷婷综合久久
|
久久精品中文騷妇女内射
|
国内精品久久久久久野外
|
91秦先生久久久久久久
|