第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

碼仔漫畫(huà)|重學(xué)設(shè)計(jì)模式之裝飾者模式

码仔带你学习设计模式

https://img3.sycdn.imooc.com/5fd0d6060001210607250492.jpg

https://img4.sycdn.imooc.com/5fd0d6070001f14907250492.jpg

https://img2.sycdn.imooc.com/5fd0d6070001111007250492.jpg

https://img1.sycdn.imooc.com/5fd0d6080001565d07250492.jpg

https://img1.sycdn.imooc.com//5fd0d69d00014e2007250492.jpg

https://img1.sycdn.imooc.com/5fd0d60900010f0707250492.jpg

https://img1.sycdn.imooc.com//5fd0d6be0001524b07250492.jpg

https://img1.sycdn.imooc.com/5fd0d60d0001d2ad07250492.jpg

https://img3.sycdn.imooc.com/5fd0d60e0001093507250492.jpg

https://img1.sycdn.imooc.com//5fd0d6de0001450607250492.jpg

https://img4.sycdn.imooc.com/5fd0d61a0001b12307250492.jpg

https://img3.sycdn.imooc.com/5fd0d61b0001989107250492.jpg

https://img1.sycdn.imooc.com//5fd0d7020001235207250492.jpg

https://img4.sycdn.imooc.com/5fd0d61c0001521806400432.jpg

https://img1.sycdn.imooc.com//5fd0d71f0001235207250492.jpg

https://img2.sycdn.imooc.com/5fd0d61d0001c6ce07250492.jpg

代码

抽象基类

public abstract class 英雄 {  public abstract int 攻击()  public abstract int 冷却()
   ........
}

实现基类

public class 李白 extends 英雄 {   @Override
   public int 冷却(){      return 5;
  }
   ........
}

Buff 抽象类

public abstract Buff extends 英雄 {   public abstract int 攻击()  public abstract int 冷却()
   ........
}

不同 Buff 的实现类

public 红buff extends Buff {   private 英雄 英雄;   public 红buff(英雄 英雄){        this.英雄 = 英雄;
    }     @Override
   public int 攻击() {     return 英雄.攻击() + 红buff额外攻击;
   }
   .........
 
}public 蓝buff extends Buff {   private 英雄 英雄;   public 蓝buff(英雄 英雄){        this.英雄 = 英雄;
    }    @Override
   public int 冷却() {
     return 英雄.冷却()  + 蓝buff额外减少的冷却值;
   }
   .........

}

客户端

public class Client {
    public static void main(String[] args) {        // 没有buff的英雄
        英雄 无buff李白 = new 李白();       
        // 打了红
        红buff 红buff李白 = new 红buff(无buff李白);        // 再来个篮
        篮buff 红蓝buff李白 = new 篮buff(红buff李白);

    }
}

注意:以上代码块用中文编写类名、变量名是为了让大家更好的理解,在实战过程中记得替换成相对应的英文。

总结

https://img1.sycdn.imooc.com//5fd0d736000182eb06400485.jpg

出自《Head first 设计模式》

PS:

内容是我之前写过的,改成了漫画的形式。

大家觉得不错就点个赞,如有建议可以欢迎留言讨论。


點(diǎn)擊查看更多內(nèi)容
2人點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
全棧工程師
手記
粉絲
67
獲贊與收藏
1544

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶(hù)
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消