zoukankan
html css js c++ java
责任链
1:意图
为解除请求的发送者和接收者之间耦合,而使多个对象都有机会处理这个请求。将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它。
2:类图
3:代码
namespace
Bll.ChainOfResponsibility
{
public
class
MSGEntity
{
//
信息内容
private
string
content;
public
string
Content
{
get
{
return
content; }
set
{ content
=
value; }
}
//
审核级别
private
int
level
=
0
;
public
int
Level
{
get
{
return
level; }
set
{ level
=
value; }
}
}
public
abstract
class
Man
{
protected
Man _man;
public
abstract
void
Read(MSGEntity entity);
public
void
SetSuccessor(Man man)
{
this
._man
=
man;
}
}
public
class
Employee : Man
{
const
int
level
=
1
;
public
override
void
Read(MSGEntity entity)
{
if
(
object
.Equals(level, entity.Level))
{
//
}
else
if
(
base
._man
!=
null
)
{
_man.Read(entity);
}
}
}
public
class
Leader : Man
{
const
int
level
=
2
;
public
override
void
Read(MSGEntity entity)
{
if
(
object
.Equals(level, entity.Level))
{
//
}
else
if
(
base
._man
!=
null
)
{
_man.Read(entity);
}
}
}
public
class
Manage : Man
{
const
int
level
=
3
;
public
override
void
Read(MSGEntity entity)
{
if
(
object
.Equals(level, entity.Level))
{
//
}
else
if
(
base
._man
!=
null
)
{
_man.Read(entity);
}
}
}
}
//
调用
Employee employ
=
new
Employee();
Leader leader
=
new
Leader();
Manage manage
=
new
Manage();
employ.SetSuccessor(leader);
leader.SetSuccessor(manage);
employ.Read(
new
MSGEntity());
查看全文
相关阅读:
P2679 子串
线段树优化建边
P2444 [POI2000]病毒
P3966 [TJOI2013]单词
4327: JSOI2012 玄武密码
UVA1449 Dominating Patterns
P1250 种树
P2255 [USACO14JAN]记录奥林比克
SP283 NAPTIME
P3436 [POI2006]PRO-Professor Szu
原文地址:https://www.cnblogs.com/tommyli/p/1228254.html
最新文章
BZOJ 4305 数列的GCD
「ZJOI2014」力
一个人的高三楼
「PKUSC2018」神仙的游戏
[HNOI2008]GT考试
BBQ Hard
Leftmost Ball
[CQOI2015]选数
Luogu P4139 上帝与集合的正确用法
Luogu P2568 GCD
热门文章
Luogu P3768 简单的数学题
Codeforces Round #570 (Div. 3)
洛谷P5269 欧稳欧再次学车
二维凸包学习笔记
洛谷P5239 回忆京都
洛谷P5238 整数校验器
Link Cut Tree学习笔记
AT1145 ホリドッグ
指数序列
洛谷P1004 方格取数
Copyright © 2011-2022 走看看