策略模式的典型應用

2021-08-22 15:49:40 字數 2309 閱讀 7098

做了乙個小東西,裡面有多個角色,每個角色都有特殊的選單項,現使用策略模式對其簡單實現。

關於策略模式的介紹請參考其他書籍。

下面是專案架構和實現:

架構:

實現:imenustrategy.cs

using system;

using system.collections.generic;

using system.linq;

using system.text;

namespace strategypattern.bll

}developer.cs

using system;

using system.collections.generic;

using system.linq;

using system.text;

namespace strategypattern.bll}}

tester.cs

using system;

using system.collections.generic;

using system.linq;

using system.text;

namespace strategypattern.bll}}

commonuser.cs

using system;

using system.collections.generic;

using system.linq;

using system.text;

namespace strategypattern.bll}}

menuop.cs

using system;

using system.collections.generic;

using system.linq;

using system.text;

namespace strategypattern.bll

public void setmenu(system.windows.forms.menustrip ms)}}

介面:

**:using system;

using system.collections.generic;

using system.componentmodel;

using system.data;

using system.drawing;

using system.linq;

using system.text;

using system.windows.forms;

namespace strategypattern

private static string role;

public static string role

set}

private void btnsubmit_click(object sender, eventargs e)

break;

case "t":

case "t":

if (txtpwd.text.trim() == "t")

break;

case "c":

case "c":

if (txtpwd.text.trim() == "c")

break;}}

}}不同的登入介面:

開發:

測試 :

經理:

**:using system;

using system.collections.generic;

using system.componentmodel;

using system.data;

using system.drawing;

using system.linq;

using system.text;

using system.windows.forms;

namespace strategypattern

private void mainform_load(object sender, eventargs e)}}

}

策略模式典型應用

filenamefilter 這個介面,它在 io 包下面。這個介面只有乙個方法。boolean accept file dir,string name 這個方法只有乙個用處,就是給 file 類裡面的 list 方法呼叫。public string list filenamefilter filt...

策略模式的典型應用

做了乙個小東西,裡面有多個角色,每個角色都有特殊的選單項,現使用策略模式對其簡單實現。關於策略模式的介紹請參考其他書籍。下面是專案架構和實現 架構 實現 imenustrategy.cs using system using system.collections.generic using syst...

設計模式應用三 策略模式

商場打折 策略可以簡單分為 原價購買 滿減 返利三種策略 系統的操作都要有日誌記錄,通常會把日誌記錄在資料庫裡面,方便後續的管理,但是在記錄日誌到資料庫的時候,可能會發生錯誤,比如暫時連不上資料庫了,那就先記錄在檔案裡面。日誌寫到資料庫與檔案中是兩種演算法,但呼叫方不關心,只負責寫就是 根據狀態進行...