装饰设计模式,就是多级继承,需要什么继承后再写方法。
/**
* 装饰设计模式
*/
public class DecorationDesignPattern {
public static void main(String[] args) {
// Student stu = new Student();
// stu.code();
//
// System.out.println("-----------");
//
// School school = new School(new Student());
// school.code();
//
// System.out.println("-----------");
Employee emp = new Employee(new School(new Student()));
emp.code();
}
}
模板设计模式,需要自定义模板
// 模板设计模式
public class TemplateTest {
public static void main(String[] args) {
Template lt = new LoopTemplate();
long result = lt.showTime();
System.out.println(result);
}
}