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());
查看全文
相关阅读:
【网易官方】极客战记(codecombat)攻略-地牢-矮人骚乱
Digital Twin——IoT的下一个浪潮
PPT |《Kubernetes的兴起》
视频课程 | Kubernetes的兴起
干货 | 京东云原生容器—SpringCloud实践(一)
干货 | 独创分布式网络负载均衡最佳实践
视频课程 | 云原生下的Serverless浅谈
ubuntu不能联网的问题
boost库在windows上的安装
python tkinter
原文地址:https://www.cnblogs.com/tommyli/p/1228254.html
最新文章
系统芯片(SOC)架构- Aviral Mittal
H.265 HD 和H.265 4K Video Encoder IP Core
SOC,System on-a-Chip技术初步
编译器设计-代码优化
语法和语义和错误;
JAVA代码中可使用中文类名,变量名,对象名,方法名.
JAVA 程序编译过程;编辑器,编译器和解释器
编程语言的发展
计算机组成 数据处理过程
JAVA 代码中使用中文的办法
热门文章
JDK环境变量配置
【网易官方】极客战记(codecombat)攻略-地牢-洞穴求生
【网易官方】极客战记(codecombat)攻略-地牢-Kithgard 斗殴
【网易官方】极客战记(codecombat)攻略-地牢-毁灭天使
【网易官方】极客战记(codecombat)攻略-地牢-Kithgard 之门
【网易官方】极客战记(codecombat)攻略-地牢-严酷考验 B
【网易官方】极客战记(codecombat)攻略-地牢-严酷考验 A
【网易官方】极客战记(codecombat)攻略-地牢-严酷考验
【网易官方】极客战记(codecombat)攻略-地牢-蜿蜒峡谷
【网易官方】极客战记(codecombat)攻略-地牢-Kithmaze 最终历险
Copyright © 2011-2022 走看看