一、策略模式(Strategy Pattern)
生活随笔
收集整理的這篇文章主要介紹了
一、策略模式(Strategy Pattern)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、策略模式定義
???? 策略模式定義了算法族,分別封裝起來,讓它們之間可以互相替換,此模式讓算法的變化獨立于算法的客戶。
2、類圖3、實例 abstract class Duck {IFly ifly;public void Fly(){ifly.Fly();} } interface IFly {void Fly(); } class FlyWithWings : IFly {public void Fly(){Console.WriteLine(“Fling with wings.”)} } Class FlyWithRocket() {public void Fly(){Console.WriteLine(“Fling with rocket.”)} }class Duck1 : Duck {public Duck1(){ifly=new FlyWithRocket();} }
轉載于:https://www.cnblogs.com/Lonfee/archive/2011/05/05/2037523.html
總結
以上是生活随笔為你收集整理的一、策略模式(Strategy Pattern)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android log显示
- 下一篇: [转]const使用详解