当前位置: 首页 > news >正文

装饰者模式

代码详解:【设计模式】Java 设计模式之装饰者模式(Decorator)_java 装饰者模式-CSDN博客

// 抽象构件角色
public interface Component {void operation();
}// 具体构件角色
public class ConcreteComponent implements Component {@Overridepublic void operation() {System.out.println("执行具体构件对象的操作");}
}// 装饰角色
public class Decorator implements Component {protected Component component;public Decorator(Component component) {this.component = component;}@Overridepublic void operation() {if (component != null) {component.operation();}}
}// 具体装饰角色A
public class ConcreteDecoratorA extends Decorator {public ConcreteDecoratorA(Component component) {super(component);}@Overridepublic void operation() {super.operation();addedFunctionA();}public void addedFunctionA() {System.out.println("为构件对象添加功能A");}
}// 具体装饰角色B
public class ConcreteDecoratorB extends Decorator {public ConcreteDecoratorB(Component component) {super(component);}@Overridepublic void operation() {super.operation();addedFunctionB();}public void addedFunctionB() {System.out.println("为构件对象添加功能B");}
}

 装者模式的应用:

-mybatis 里的缓存:

http://www.lryc.cn/news/509181.html

相关文章:

  • 【机器学习】当教育遇上机器学习:打破传统,开启因材施教新时代
  • 【蓝桥杯每日一题】分糖果——DFS
  • information_schema是什么?
  • 案例分析-THC7984设计问题报告
  • HarmonyOS NEXT 技术实践-基于基础视觉服务的多目标识别
  • 【python】银行客户流失预测预处理部分,独热编码·标签编码·数据离散化处理·数据筛选·数据分割
  • 使用 docker ps 查不到刚刚创建的容器
  • vue2+element 前端表格下载
  • MySQL使用LOAD DATA INFILE方式导入文本文件
  • 【从零开始入门unity游戏开发之——unity篇02】unity6基础入门——软件下载安装、Unity Hub配置、安装unity编辑器、许可证管理
  • SpringBootWeb 篇-深入了解 SpringBoot + Vue 的前后端分离项目部署上线与 Nginx 配置文件结构
  • 优化程序中的数据:从代数到向量解
  • 【Web】2024“国城杯”网络安全挑战大赛决赛题解(全)
  • 基于ceres优化的3d激光雷达开源算法
  • 【FAQ】HarmonyOS SDK 闭源开放能力 — Vision Kit(2)
  • 【LeetCode】726、原子的数量
  • VMware虚拟机三种网络工作模式
  • 14-zookeeper环境搭建
  • [搜广推]王树森推荐系统笔记——矩阵补充最近邻查找
  • Unity3D * 粒子特效 * Particle System
  • 【基础篇】1. JasperSoft Studio编辑器与报表属性介绍
  • 数据结构:算法篇:快速排序;直接插入排序
  • WebAPI编程(第一天,第二天)
  • 查看MySQL存储引擎方法,表操作
  • 【Python教程】Python3基础篇之Number(数字)
  • 基于openEuler22.09部署OpenStack Yoga云平台(一)
  • I.MX6U 启动方式详解
  • 施耐德变频器ATV320系列技术优势:创新与安全并重
  • 系统思考—全局思维
  • Windows如何切换用户访问局域网共享文件夹,如何切换网上邻居的账户