装饰设计模式
来源:互联网 发布:js style.marginleft 编辑:程序博客网 时间:2024/05/22 12:04
/*装饰设计模式:当想要对已有的对象进行功能增强时,可以定义类,将已有对象传入,基于已有的功能,并提供加强功能。那么自定义的该类称为装饰类。装饰类通常会通过构造方法接收被装饰的对象。并基于被装饰的对象的功能,提供更强的功能。*/class Person{public void chifan(){System.out.println("吃饭");}}class SuperPerson{private Person p;SuperPerson(Person p){this.p = p;}public void superChifan(){System.out.println("开胃酒");p.chifan();System.out.println("甜点");System.out.println("来一根");}}class PersonDemo{public static void main(String[] args) {Person p = new Person();SuperPerson sp = new SuperPerson(p);sp.superChifan();}}class SuperPerson{private Person p;SuperPerson(Person p){this.p = p;}public void superChifan(){System.out.println("开胃酒");p.chifan();System.out.println("甜点");System.out.println("来一根");}}class PersonDemo{public static void main(String[] args) {Person p = new Person();SuperPerson sp = new SuperPerson(p);sp.superChifan();}}class SuperPerson{private Person p;SuperPerson(Person p){this.p = p;}public void superChifan(){System.out.println("开胃酒");p.chifan();System.out.println("甜点");System.out.println("来一根");}}class PersonDemo{public static void main(String[] args) {Person p = new Person();SuperPerson sp = new SuperPerson(p);sp.superChifan();}}}}class PersonDemo{public static void main(String[] args) {Person p = new Person();SuperPerson sp = new SuperPerson(p);sp.superChifan();}}class PersonDemo{public static void main(String[] args) {Person p = new Person();SuperPerson sp = new SuperPerson(p);sp.superChifan();}}class PersonDemo{public static void main(String[] args) {Person p = new Person();SuperPerson sp = new SuperPerson(p);sp.superChifan();}}
0 0
- 设计模式---装饰模式
- 设计模式:装饰模式
- 设计模式------装饰模式
- 设计模式--装饰模式
- 设计模式--装饰模式
- 设计模式--装饰模式
- 设计模式 装饰模式
- 设计模式----装饰模式
- 设计模式-【装饰模式】
- 设计模式--装饰模式
- 设计模式装饰模式
- 设计模式 - 装饰模式
- 设计模式-----装饰模式.
- 设计模式-----装饰模式.
- [ 设计模式 ] 装饰模式!
- 设计模式:装饰模式
- 设计模式 - 装饰模式
- 设计模式 - 装饰模式
- 讲故事,学(Java)设计模式—观察者模式
- 高斯日记
- 数据类型基本功能介绍
- Weka and Hadoop
- misc device
- 装饰设计模式
- ORA-12520解决办法
- h264 profile & level
- windows 8.1 下91手机助手解决方案
- ldap(一)
- Unity手游之路<九>自动寻路Navmesh之高级主题
- ffmpeg 实现音频aac编码
- MVC实现通用的增删改查。使用接口(三)学习
- Mysql数据库学习