/* * GUIFactory example */abstractclassGUIFactory{publicstaticGUIFactorygetFactory(){intsys=readFromConfigFile("OS_TYPE");if(sys==0){returnnewWinFactory();}else{returnnewOSXFactory();}}publicabstractButtoncreateButton();}classWinFactoryextendsGUIFactory{publicButtoncreateButton(){returnnewWinButton();}}classOSXFactoryextendsGUIFactory{publicButtoncreateButton(){returnnewOSXButton();}}abstractclassButton{publicabstractvoidpaint();}classWinButtonextendsButton{publicvoidpaint(){System.out.println("I'm a WinButton");}}classOSXButtonextendsButton{publicvoidpaint(){System.out.println("I'm an OSXButton");}}publicclassApplication{publicstaticvoidmain(String[]args){GUIFactoryfactory=GUIFactory.getFactory();Buttonbutton=factory.createButton();button.paint();}// Output is either:// "I'm a WinButton"// or:// "I'm an OSXButton"}
อ้างอิง
กันยายน 11, 2021
แบบโรงงานย, บทความน, ไม, การอ, างอ, งจากแหล, งท, มาใดกร, ณาช, วยปร, บปร, งบทความน, โดยเพ, มการอ, างอ, งแหล, งท, มาท, าเช, อถ, เน, อความท, ไม, แหล, งท, มาอาจถ, กค, ดค, านหร, อลบออก, เร, ยนร, าจะนำสารแม, แบบน, ออกได, อย, างไรและเม, อไร, งกฤษ, abstract, factory, . bthkhwamniimmikarxangxingcakaehlngthimaidkrunachwyprbprungbthkhwamni odyephimkarxangxingaehlngthimathinaechuxthux enuxkhwamthiimmiaehlngthimaxacthukkhdkhanhruxlbxxk eriynruwacanasaraemaebbnixxkidxyangiraelaemuxir aebborngnganyx xngkvs abstract factory pattern epnrupaebbkar Design Software thiichwithikarrwmklum Factory thiimekiywkhxngknthimirupaebbediywkniwdwykn thaihsamarth Encapsulate klumkhxng Factory thiimekiywkhxngknthimirupaebbediywkniwdwyknodyphuichcaeriykichngan Factory phan Abstract Interface sungcathahnathisrang Object thiehmaasmihaekphuichidexngxtonmtihruxxacihphuichkahnd Factory Object thitxngkarsrangiddwytwexng in Abstract Factory Design Pattern nicaaeykraylaexiydkar Implement khxng Object xxkcakkareriykich enuxha 1 withikarich 2 khxidepriyb 3 khxesiyepriyb 4 Class Diagram 5 twxyang 5 1 Java 6 xangxingwithikarich aekikhkarsrang Abstract Factory catxngprakxbdwykhunsmbtitxipnikkhuxinradb Abstract Factory Abstract Class Abstract Factory epntwtdsinicwacasrang Factory Object idkhunmaphan Static Method khxng Abstract Factory static method samartheriykphan Abstract Factory id inkareluxkwacasrang Factory Object idkhunmaeraxacichkarxan Configuration File hruxwakahndexngodyphuich hruxxaccatrwcdusphawaaewdlxmkhxngrabb emuxsrang Factory Object aelwcaichkar return xxkmaepn Pointer hrux Object ID khxng Factory Object nnody type caepnchnid Abstract Factory nn inkareriykichephuxihkareriykichimkhuntxkhwamaetktangkhxng Factory Object tang thithuksrangkhunmacaxnuyatihphuicheriykphanswnthiepn Abstract Interface ethanninradb Factory Object Concrete Class chnidkhxng Object thisrangmacatdsinicthitw Factory exng Object thi Factory srangcatxngepn Object thi Derive macak Abstract Class thiphuichngansamartheriykichid emux Factory Object srang Object phayin Factory Object ca type thi return catxng return xxkmaepn Abstract Class aemkhxng Object nn echnediywkb Factory Object thitxngeriykphan Abstract Interface inkareriyk Object thisrangody Factory ktxngeriykphanswnthiepn Abstract Interface khxng Object nndwykhxidepriyb aekikhephraawa Abstract Factory Design Pattern idichpraoychnkhxng Information Hiding thaihphuichimtxngsniceruxngeluxk Factory Class thiehmaasmdwytnexng singthithakephiyngaekheriykichnganphan Abstract Interface aelw Object thiehmaasmkcathuksrangihodyxtonmti ephimkhwamsamarthinkar Reuse enuxngcak Factory Class epn Concrete Class thi Derive macak Abstract Factory Class sunginkareriykicherasamartheriykphan Abstract Factory idthnthithaihemuxeratxngkarthicaephim Factory ihmlngipsamarththaidodykarsrangkhlasihmthi Derive macak Abstract Factory Class aelw Implement ihm sungcaimsngphltxkareriykichkhxngphuichthieriykphan Abstract Factory Classkhxesiyepriyb aekikhechnediywknkb Design Pattern xun Abstract Factory Design Pattern mirupaebbkarxxkaebbthikhxnkhangsbsxn xacepnkarephimkhwamsbsxnodyimcaepn epnkarephimkhwamsadwkinkar design aetephimkhwamsbsxninkarthangankhxngkhxmphiwetxrthaih Abstract Factory Design Pattern imehmaasahrbnganthitxngkarkhwamerwsunginkhxmphiwetxrthithrphyakrkhxnkhangcakd aelakarxxkaebb Abstract Factory Design Pattern catxngthanganephiminkhntxnaerk khxngkar Design dwyClass Diagram aekikh twxyang aekikhJava aekikh GUIFactory example abstract class GUIFactory public static GUIFactory getFactory int sys readFromConfigFile OS TYPE if sys 0 return new WinFactory else return new OSXFactory public abstract Button createButton class WinFactory extends GUIFactory public Button createButton return new WinButton class OSXFactory extends GUIFactory public Button createButton return new OSXButton abstract class Button public abstract void paint class WinButton extends Button public void paint System out println I m a WinButton class OSXButton extends Button public void paint System out println I m an OSXButton public class Application public static void main String args GUIFactory factory GUIFactory getFactory Button button factory createButton button paint Output is either I m a WinButton or I m an OSXButton xangxing aekikhekhathungcak https th wikipedia org w index php title aebborngnganyx amp oldid 4755733, wikipedia, วิกิ หนังสือ, หนังสือ, ห้องสมุด,