首页 > 代码库 > 装饰模式
装饰模式
People.java类
package decorate; public class People{ private String name; public People() { } public People(String name) { this.name = name; } public void operation() { System.out.println("开始装饰:"+name); } }
Finery.java类
package decorate; public class Finery extends People{ private People people; public void decorate(People people) { this.people = people; } public void operation(){ people.operation(); } }
TshirtFinery.java类
package decorate; public class TshirtFinery extends Finery { @Override public void operation() { super.operation(); this.show(); } public void show(){ System.out.println("大T衫"); } }
BigTrouserFinery.java类
package decorate; public class BigTrouserFinery extends Finery { @Override public void operation() { super.operation(); this.show(); } public void show(){ System.out.println("大裤衩"); } }
ShoeFinery.java类
package decorate; public class ShoeFinery extends Finery { @Override public void operation() { super.operation(); this.show(); } public void show(){ System.out.println("长袜子"); } }
Business.java类
package decorate; public class Business { public static void main(String[] args) { People p = new People("桂清"); TshirtFinery t = new TshirtFinery(); BigTrouserFinery b = new BigTrouserFinery(); ShoeFinery s = new ShoeFinery(); t.decorate(p); b.decorate(t); s.decorate(b); s.operation(); } }
装饰模式
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。