您的位置:首页 > 其它

设计模式

2020-01-15 11:54 169 查看

装饰设计模式,就是多级继承,需要什么继承后再写方法。

/**
* 装饰设计模式
*/
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);
}
}
  • 点赞
  • 收藏
  • 分享
  • 文章举报
一梦如意 发布了92 篇原创文章 · 获赞 1 · 访问量 1036 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: