Java设计模式之装饰设计模式(2)
2013-12-29 11:58
330 查看
package com.heima.pattern;
/**
* 装饰设计模式: BufferedReader(readLine())是对FileReader(read())功能的一种增强
* BufferedReader就是装饰类 装饰类和被装饰类一般会归属于同一个类
*/
public class TestDecorator {
public static void main(String[] args) {
Person person = new Person();
// person.eat();
SuperPerson superPerson = new SuperPerson(person);
superPerson.superEat();
}
}
// 被装饰类
class Person {
public void eat() {
System.out.println("吃饭");
}
}
// 装饰类
class SuperPerson {
private Person person = null;
// 通常用构造函数来接受一个被装饰类
public SuperPerson(Person person) {
this.person = person;
}
// 然后基于被装饰类提供更强的功能
public void superEat() {
System.out.println("开胃菜");
person.eat();
System.out.println("甜点");
}
}
/**
* 装饰设计模式: BufferedReader(readLine())是对FileReader(read())功能的一种增强
* BufferedReader就是装饰类 装饰类和被装饰类一般会归属于同一个类
*/
public class TestDecorator {
public static void main(String[] args) {
Person person = new Person();
// person.eat();
SuperPerson superPerson = new SuperPerson(person);
superPerson.superEat();
}
}
// 被装饰类
class Person {
public void eat() {
System.out.println("吃饭");
}
}
// 装饰类
class SuperPerson {
private Person person = null;
// 通常用构造函数来接受一个被装饰类
public SuperPerson(Person person) {
this.person = person;
}
// 然后基于被装饰类提供更强的功能
public void superEat() {
System.out.println("开胃菜");
person.eat();
System.out.println("甜点");
}
}
相关文章推荐
- Java与设计模式(十九)结构型--装饰器模式
- Java基础之装饰设计模式
- Java RandomAccessFile Properties 与装饰着设计模式
- [译]Java 设计模式之装饰器
- java 设计模式学习笔记九 decorator装饰模式
- java中常用的设计模式-装饰设计模式
- Java设计模式之-装饰模式
- java设计模式之装饰模式Decorator
- Java设计模式_结构型_装饰模式_是海军还是空军
- Java设计模式-装饰模式(Decorator模式)
- 设计模式之装饰模式 Decoratory Pattern java
- Java设计模式之装饰模式
- (三)Java设计模式--装饰器模式
- Java设计模式之八(装饰模式)
- 浅析Java设计模式之装饰器模式
- java设计模式之装饰模式(在i/o流中的应用)
- java设计模式之装饰模式
- Java设计模式之装饰器模式
- Java设计模式之--装饰模式
- java23种常用设计模式之装饰模式(Decorator)