首页
找靠谱产品
找解决方案
找靠谱公司
找案例
找对的人
专家智库
悬赏任务
SAAS
ToB门户
了解全球最新的ToB事件
论坛
潜水/灌水快乐,沉淀知识,认识更多同行。
ToB圈子
加入IT圈,遇到更多同好之人。
微博
Follow
记录
Doing
博客
Blog
文库
业界最专业的IT文库,上传资料也可以赚钱
下载
分享
Share
排行榜
Ranklist
相册
Album
应用中心
qidao123.com ToB IT社区-企服评测·应用市场
»
论坛
›
物联网/工业互联网
›
物联网
›
装饰者模式
返回列表
发新帖
装饰者模式
[复制链接]
发表于 2024-12-26 11:52:24
|
显示全部楼层
|
阅读模式
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要
登录
才可以下载或查看,没有账号?
立即注册
×
代码
详解:【计划模式】Java 计划模式之装饰者模式(Decorator)_java 装饰者模式-CSDN博客
// 抽象构件角色
public interface Component {
void operation();
}
// 具体构件角色
public class ConcreteComponent implements Component {
@Override
public void operation() {
System.out.println("执行具体构件对象的操作");
}
}
// 装饰角色
public class Decorator implements Component {
protected Component component;
public Decorator(Component component) {
this.component = component;
}
@Override
public void operation() {
if (component != null) {
component.operation();
}
}
}
// 具体装饰角色A
public class ConcreteDecoratorA extends Decorator {
public ConcreteDecoratorA(Component component) {
super(component);
}
@Override
public void operation() {
super.operation();
addedFunctionA();
}
public void addedFunctionA() {
System.out.println("为构件对象添加
功能
A");
}
}
// 具体装饰角色B
public class ConcreteDecoratorB extends Decorator {
public ConcreteDecoratorB(Component component) {
super(component);
}
@Override
public void operation() {
super.operation();
addedFunctionB();
}
public void addedFunctionB() {
System.out.println("为构件对象添加
功能
B");
}
}
复制
代码
装者模式的应用:
-mybatis 里的缓存:
回复
使用道具
举报
返回列表
浏览过的版块
SQL-Server
数据仓库与分析
DevOps与敏捷开发
分布式数据库
灌篮少年
+ 我要发帖
登录后关闭弹窗
登录参与点评抽奖 加入IT实名职场社区
去登录
微信订阅号
微信服务号
微信客服(加群)
H5
小程序
快速回复
返回顶部
返回列表