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());
查看全文
相关阅读:
微信小程序 --- 无法跳转到tab页面问题
CSS实现单行、多行文本溢出显示省略号(…)
Animate.css的使用
Java基础知识学习
npm 安装包失败 --- 清除npm缓存
git 学习(4) ----- git rebase
数组中的reduce 函数理解
webpack4 学习 --- 使用loader处理静态资源
IE 11 flex布局兼容性问题 ---- 不支持min-height 和flex:1
java 中的内置数据类型
原文地址:https://www.cnblogs.com/tommyli/p/1228254.html
最新文章
TTransport 概述
Scala 经典的模式匹配和尾递归
对象的深拷贝(结合泛型)
泛型之泛型方法
使用泛型和内部静态类实现栈(FILO,先进后出)
两个线程交替打印1到100
redis 基本操作
redis.conf 具体配置详解
InputStream TO byte
Dubbo特性
热门文章
js控制手机端字体大小rem
Nuxt.js 学习笔记
ThinkPHP5从零基础搭建CMS系统(二)
ThinkPHP5从零基础搭建CMS系统(一)
自己的reset.css
vue项目通过webpack打包生成的dist文件放到express环境里运行(vue+webpack+express)
移动端h5下ul实现横向滚动css代码
判断当前设备是移动端或者PC端
微信公众号一键关注解决办法
小程序上拉下拉共存时不可使用scroll-view的解决方法
Copyright © 2011-2022 走看看