我們項(xiàng)目實(shí)踐中,使用了簡(jiǎn)單工廠方法來解決客戶端決策的問題救斑,如下:
Strategy StrategyFactory.getByType(int type);
個(gè)人理解换淆,“改變條件語句復(fù)雜”的本質(zhì)還是要讓類符合開閉原則哗总,降低業(yè)務(wù)開發(fā)的復(fù)雜度,太多的if else 會(huì)導(dǎo)致整個(gè)類變得臃腫倍试,容易出錯(cuò)
策略模式(strategy pattern)策略模式(Strategy pattern) 定義 Define a family of algorithms, encapsulate each one, and make...