码迷,mamicode.com
首页 > 编程语言 > 详细

java中23种设计模式之12-装饰模式(decorator pattern)

时间:2015-04-02 22:08:11      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!