0%
装饰设计模式代码示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| interface Coder { public void code(); }
class Student implements Coder {
@Override public void code() { System.out.println("javase"); System.out.println("javaweb"); } }
class HeiMaStudent implements Coder { private Student s; public HeiMaStudent(Student s) { this.s = s; }
@Override public void code() { s.code(); System.out.println("ssh"); System.out.println("数据库"); System.out.println("大数据"); System.out.println("..."); } }
|
装饰设计模式的好处
耦合性不强,被装饰的类的变化与装饰类的变化无关