package decorator;
publicclass test {
publicstaticvoidmain(String[] args) {
Person p1 = new Person("Tom", 12);
Sneakers sn = new Sneakers();
Suit su = new Suit();
BigTrouser bt = new BigTrouser();
TShirts ts = new TShirts();
ts.Decorate(p1);
bt.Decorate(ts);
su.Decorate(bt);
sn.Decorate(su);
sn.show();
}
}
装饰模式在web开发中尤其常见,在filter中,用的就是装饰模式,在excute前后添加过滤的方法。package decorator;public class Person { private String name; private int age; public Person() { super(); } public Person(