@Override public void dressup(Person person) { System.out.println(person.getName() + "穿衣服"); }
}
class TrousersDressUp extends DressUp {
@Override public void dressup(Person person) { System.out.println(person.getName() + "穿裤子"); }
}
class ShoesDressUp extends DressUp {
@Override public void dressup(Person person) { System.out.println(person.getName() + "穿鞋子"); }
}
客户端:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
public class Client {
public static void main(String[] args) { Person person = new Person("小白"); DressUp du1 = new ClothesDressUp(); du1.dressup(person); DressUp du2 = new TrousersDressUp(); du2.dressup(person); DressUp du3 = new ShoesDressUp(); du3.dressup(person); } }
public static void main(String[] args) { Person person = new Man(); Person decorator = new Decorator(person); System.out.println("======第一种打扮======="); ClothesDecorator cd = new ClothesDecorator(decorator); TrousersDecorator td = new TrousersDecorator(cd); td.decorate(); System.out.println("======第二种打扮======="); ShoesDecorator sd = new ShoesDecorator(person); sd.decorate(); } }