設計模式-工廠方法模式-靜態工廠方法模式
阿新 • • 發佈:2021-02-01
技術標籤:設計模式
1、靜態工廠方法模式:同個類內,不同靜態方法分別建立不同的例項物件,這些例項物件類都繼承同個介面
2、簡單程式碼如下:
/** * @ClassName StatisFactoryMethod * @Description 靜態工廠方法模式:跟多個工廠方法模式類似,多個方法分別生產對應的物件,只不過方法都是靜態的 * @Author hs * @Date 2021/1/31 14:17 * @Version 1.0 */ public class StatisFactoryMethod { public static Map produceHashMap(){ return new HashMap(); } public static Map produceLinkHashMap(){ return new LinkedHashMap(); } public static Map produceTreeMap(){ return new TreeMap(); } }