利用策略模式優化過多 if else 代碼

前言 本次來一點實際開發中會用到的小技巧。 比如平時大家是否都會寫類似這樣的代碼:   if(a){    //dosomething }else if(b){    //doshomething }else if(c){    //doshomething } else{    ////doshomething } 條件少還好,一旦 elseif 過多這裏的邏輯將會比較混亂,並很容易出錯。 比
相關文章
相關標籤/搜索