国产乱人视频免费观看网站,九九精品视频在线观看,九九久re8在线精品视频,日韩久久精品五月综合

<menu id="zjelp"></menu>

    <th id="zjelp"><tbody id="zjelp"><form id="zjelp"></form></tbody></th>
    <small id="zjelp"><menuitem id="zjelp"></menuitem></small>
  • <small id="zjelp"></small>

    <address id="zjelp"></address>
    <address id="zjelp"></address>
    Java設(shè)計模式之抽象工廠模式

    Java設(shè)計模式之抽象工廠模式

    ID:32974693

    大?。?58.74 KB

    頁數(shù):3頁

    時間:2019-02-18

    Java設(shè)計模式之抽象工廠模式_第1頁
    Java設(shè)計模式之抽象工廠模式_第2頁
    Java設(shè)計模式之抽象工廠模式_第3頁
    資源描述:

    《Java設(shè)計模式之抽象工廠模式》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫。

    1、一、抽象工廠模式(AbstractFactory)抽象工廠模式提供一個創(chuàng)建一系列相關(guān)或相互依賴對象的接口,而無需指定它們具體的類。抽象工廠(AbstractFactory)模式,又稱工具箱(Kit或Toolkit)模式。二、創(chuàng)建過程如下一個具體工廠創(chuàng)建一個產(chǎn)品族,一個產(chǎn)品族是不同系列產(chǎn)品的組合,產(chǎn)品的創(chuàng)建的邏輯分在在每個具體工廠類中。所有的具體工廠繼承自同一個抽象工廠。客戶端創(chuàng)建不同產(chǎn)品族的工廠,產(chǎn)品族的工廠創(chuàng)建具體的產(chǎn)品對客戶端是不可見的。增加新的產(chǎn)品族時,需要增加具體工廠類,符合OCP原則。增加新產(chǎn)品時,需要修改具體工廠類和增加產(chǎn)品類,不符合

    2、OCP原則如果沒有應(yīng)對“多系列對象創(chuàng)建”的需求變化,則沒有必要使用抽象工廠模式,這時候使用簡單的靜態(tài)工廠完全可以。三、一個簡單的實例//產(chǎn)品Plant接口publicinterfaceIPlant{}//具體產(chǎn)品PlantA,PlantBpublicclassPlantAimplementsIPlant{publicPlantA(){System.out.println("createPlantA!");}publicvoiddoSomething(){System.out.println("PlantAdosomething...");}}pu

    3、blicclassPlantBimplementsIPlant{publicPlantB(){System.out.println("createPlantB!");}publicvoiddoSomething(){System.out.println("PlantBdosomething...");}}//產(chǎn)品Fruit接口publicinterfaceIFruit{}//具體產(chǎn)品FruitA,F(xiàn)ruitBpublicclassFruitAimplementsIFruit{publicFruitA(){System.out.println("c

    4、reateFruitA!");}publicvoiddoSomething(){System.out.println("FruitAdosomething...");}}publicclassFruitBimplementsIFruit{publicFruitB(){System.out.println("createFruitB!");}publicvoiddoSomething(){System.out.println("FruitBdosomething...");}}//抽象工廠方法publicinterfaceAbstractFacto

    5、ry{publicIPlantcreatePlant();publicIFruitcreateFruit();}//具體工廠方法publicclassFactoryAimplementsAbstractFactory{publicIPlantcreatePlant(){returnnewPlantA();}publicIFruitcreateFruit(){returnnewFruitA();}}publicclassFactoryBimplementsAbstractFactory{publicIPlantcreatePlant(){retur

    6、nnewPlantB();}publicIFruitcreateFruit(){returnnewFruitB();}}

    當(dāng)前文檔最多預(yù)覽五頁,下載文檔查看全文

    此文檔下載收益歸作者所有

    當(dāng)前文檔最多預(yù)覽五頁,下載文檔查看全文
    溫馨提示:
    1. 部分包含數(shù)學(xué)公式或PPT動畫的文件,查看預(yù)覽時可能會顯示錯亂或異常,文件下載后無此問題,請放心下載。
    2. 本文檔由用戶上傳,版權(quán)歸屬用戶,天天文庫負(fù)責(zé)整理代發(fā)布。如果您對本文檔版權(quán)有爭議請及時聯(lián)系客服。
    3. 下載前請仔細(xì)閱讀文檔內(nèi)容,確認(rèn)文檔內(nèi)容符合您的需求后進(jìn)行下載,若出現(xiàn)內(nèi)容與標(biāo)題不符可向本站投訴處理。
    4. 下載文檔時可能由于網(wǎng)絡(luò)波動等原因無法下載或下載錯誤,付費完成后未能成功下載的用戶請聯(lián)系客服處理。