ublic class Demo7_Wrap {
/**
* @param args
* 装饰设计模式
* 让被包装的对象变的更加强大
*/
public static void main(String[] args) {
Student s = new Student();
s.code();
System.out.println("-------------------");
ItcastStudent is = new ItcastStudent(s);
is.code();
}
}
interface Coder {
public void code();
}
class Student implements Coder {
@Override
public void code() {
System.out.println("javase");
System.out.println("javaweb");
}
}
class ItcastStudent implements Coder{
private Student s;
public ItcastStudent(Student s) {
this.s = s;
}
@Override
public void code() {
s.code();
System.out.println("数据库");
System.out.println("安卓");
System.out.println("ssh");
System.out.println(".......");
}
} |
|