设计模式-装饰者设计模式
来源:互联网 发布:js 当前页面url 编辑:程序博客网 时间:2024/06/16 17:06
1.装饰者设计模式的公共接口
public interface Coder {public void coder();}
2.被装饰者
public class Student implements Coder{@Overridepublic void coder() {System.out.println("我会C语言");System.out.println("我会Java语言");}}
3.定义装饰者
public class HPEStudent implements Coder{//别人传一个Studentprivate Student student;public HPEStudent(Student student) {this.student = student;}@Overridepublic void coder() {//包装模式,对学生进行包装,不管是什么学生都可以,只要穿个学生就可以了student.coder();System.out.println("我学会了框架");System.out.println("我学会了数据库");}}
4.测试类
public class Demo {public static void main(String[] args) {//创建装饰模式对象,传入学生对象,对学生进行包装HPEStudent hpeStudent = new HPEStudent(new Student());hpeStudent.coder();}}
0 0
- 装饰者设计模式
- 设计模式 - 装饰者
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- 装饰者设计模式
- D3D11地形渲染教程十九之Foliage(植被的渲染)
- HTML标签----图文详解
- 在github上fork的相关操作
- 第十七章 集合Collection 1
- Whoere即时聊天App(三)客户端实现+服务部署
- 设计模式-装饰者设计模式
- linux驱动的异步同步通知机制
- TreeSet部分源码解析
- 【蓝桥杯】算法提高 7-2求arccos值
- 面向对象的原则
- ACM 海贼王之伟大航路(深搜剪枝)
- Android之DOM解析XML
- 读“深度探索C++模型”的一些理解
- conda下载很慢怎么办?