装扮模式:按照书上的代码自己写了一下,感觉不太好理解,等下次理解了再来补充一下: package tom.java.com; public class ZhuangBan { public static void main(String[] args) { Human tom = new Human("tom"); Tshirt ts = new Tshirt(); FootballShoes fbs = new FootballShoes(); Trousous tr = new Trousous(); ts.Decory(tom); fbs.Decory(ts); tr.Decory(fbs); tr.showDress(); } } class Human{ private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public Human(String newName){ this.setName(newName); } public Human(){} public void showDress(){ System.out.println("装扮的:"+this.getName()); } } class Finery extends Human{ public Finery(String newName) { super(newName); // TODO Auto-generated constructor stub } public Finery() { } private Human human; public Human getHuman() { return human; } public void setHuman(Human human) { this.human = human; } public void Decory(Human newHuman){ this.setHuman(newHuman); } @Override public void showDress(){ if(human != null){ human.showDress(); } } } class Tshirt extends Finery{ public Tshirt(String newName) { super(newName); // TODO Auto-generated constructor stub } public Tshirt() { } @Override public void showDress(){ System.out.println("T-shirt"); super.showDress(); } } class FootballShoes extends Finery{ public FootballShoes(String newName) { super(newName); // TODO Auto-generated constructor stub } public FootballShoes() { } @Override public void showDress(){ System.out.println("FootballShoes"); super.showDress(); } } class Trousous extends Finery{ public Trousous(String newName) { super(newName); // TODO Auto-generated constructor stub } public Trousous() { } @Override public void showDress(){ System.out.println("Trousous"); super.showDress(); } } </textarea > <br />