国产高清吹潮免费视频,老熟女@tubeumtv,粉嫩av一区二区三区免费观看,亚洲国产成人精品青青草原

二維碼
企資網(wǎng)

掃一掃關(guān)注

當(dāng)前位置: 首頁(yè) » 企資快報(bào) » 科普知識(shí) » 正文

C也設(shè)計(jì)模式-策略模式(Strategy)

放大字體  縮小字體 發(fā)布日期:2022-12-19 03:25:55    作者:百里海蕓    瀏覽次數(shù):60
導(dǎo)讀

定義Strategy設(shè)計(jì)模式定義了一系列算法,分別封裝起來(lái),并使它們之間可以互相替換。此模式允許讓算法得變化獨(dú)立于使用它得客戶。OO設(shè)計(jì)原則封裝變化多用組合,少用繼承針對(duì)接口編程,不針對(duì)實(shí)現(xiàn)編程類圖策略模型類圖

定義

Strategy設(shè)計(jì)模式定義了一系列算法,分別封裝起來(lái),并使它們之間可以互相替換。此模式允許讓算法得變化獨(dú)立于使用它得客戶。

OO設(shè)計(jì)原則
  • 封裝變化
  • 多用組合,少用繼承
  • 針對(duì)接口編程,不針對(duì)實(shí)現(xiàn)編程類圖

    策略模型類圖

    代碼

    namespace DesignPattern.Strategy.Structural{ /// <summary> /// The 'Context' class /// </summary> public class Context { Strategy strategy; public Context(Strategy strategy) { this.strategy = strategy; } public void ContextInterface() { strategy.AlgorithmInterface(); } } /// <summary> /// The 'Strategy' class /// </summary> public abstract class Strategy { public abstract void AlgorithmInterface(); } /// <summary> /// The 'StrategyA' class /// </summary> public class StrategyA: Strategy { public override void AlgorithmInterface() { Console.WriteLine("ConcreteStrategyA AlgorithmInterface."); } } /// <summary> /// The 'StrategyB' class /// </summary> public class StrategyB : Strategy { public override void AlgorithmInterface() { Console.WriteLine("ConcreteStrategyB.AlgorithmInterface."); } } /// <summary> /// The 'StrategyC' class /// </summary> public class StrategyC : Strategy { public override void AlgorithmInterface() { Console.WriteLine("ConcreteStrategyC.AlgorithmInterface."); } } /// <summary> /// MainApp startup class for Structural /// </summary> public class Program { private static void Main(string[] args) { Context context; context = new Context(new StrategyA()); context.ContextInterface(); context = new Context(new StrategyB()); context.ContextInterface(); context = new Context(new StrategyC()); context.ContextInterface(); } }}

    輸出結(jié)果

    ConcreteStrategyA AlgorithmInterface.ConcreteStrategyB.AlgorithmInterface.ConcreteStrategyC.AlgorithmInterface.

  •  
    (文/百里海蕓)
    打賞
    免責(zé)聲明
    本文為百里海蕓推薦作品?作者: 百里海蕓。歡迎轉(zhuǎn)載,轉(zhuǎn)載請(qǐng)注明原文出處:http://biorelated.com/qzkb/show-106362.html 。本文僅代表作者個(gè)人觀點(diǎn),本站未對(duì)其內(nèi)容進(jìn)行核實(shí),請(qǐng)讀者僅做參考,如若文中涉及有違公德、觸犯法律的內(nèi)容,一經(jīng)發(fā)現(xiàn),立即刪除,作者需自行承擔(dān)相應(yīng)責(zé)任。涉及到版權(quán)或其他問(wèn)題,請(qǐng)及時(shí)聯(lián)系我們郵件:weilaitui@qq.com。
     

    Copyright ? 2016 - 2023 - 企資網(wǎng) 48903.COM All Rights Reserved 粵公網(wǎng)安備 44030702000589號(hào)

    粵ICP備16078936號(hào)

    微信

    關(guān)注
    微信

    微信二維碼

    WAP二維碼

    客服

    聯(lián)系
    客服

    聯(lián)系客服:

    在線QQ: 303377504

    客服電話: 020-82301567

    E_mail郵箱: weilaitui@qq.com

    微信公眾號(hào): weishitui

    客服001 客服002 客服003

    工作時(shí)間:

    周一至周五: 09:00 - 18:00

    反饋

    用戶
    反饋