标签:
class Girl { public void showAppearance() { System.out.println("the girl: face without make up"); } } class TakeFlower extends Girl { Girl girl=null; public TakeFlower(Girl girl) { this.girl=girl; } public void showAppearance() { girl.showAppearance(); takeFlower(); } public void takeFlower() { System.out.println(" take flower"); } } class TakeNecklace extends Girl { Girl girl=null; public TakeNecklace(Girl girl) { this.girl=girl; } public void showAppearance() { girl.showAppearance(); takeNecklace(); } public void takeNecklace() { System.out.println(" take necklace"); } } class TakeEarrings extends Girl { Girl girl=null; public TakeEarrings(Girl girl) { this.girl=girl; } public void showAppearance() { girl.showAppearance(); takeEarrings(); } public void takeEarrings() { System.out.println(" take earrings"); } } public class DecoratorPatternTest { public static void main(String[] args) { Girl aGirl=new TakeNecklace(new TakeFlower(new Girl())); aGirl.showAppearance(); aGirl=new TakeFlower(new TakeEarrings(new Girl())); aGirl.showAppearance(); } }java中23种设计模式之12-装饰模式(decorator pattern)
标签:
原文地址:http://www.cnblogs.com/wudymand/p/4388326.html