The abstract factory model is a further extension of the factory method model:
1 //Abstract CPU Interface2 Interfacecpu{3 Public voidmethod ();4 }5 6 //Specific CPU class7 classCpuaImplementscpu{8 9 @OverrideTen Public voidmethod () { One //Business code A } - - } the - classCpubImplementscpu{ - - @Override + Public voidmethod () { - //Business code + } A at } - - //Abstract Motherboard Interface - Interfacemainboard{ - Public voidmethod (); - } in - //Specific Motherboard class to classMainboardaImplementsmainboard{ + - @Override the Public voidmethod () { * //Business code $ }Panax Notoginseng - } the + classMainboardbImplementsmainboard{ A the @Override + Public voidmethod () { - //Business code $ } $ - } - the //Abstract Factory Interface - Interfacefactory{Wuyi PublicCPU createcpu (); the Publicmainboard Createmainboard (); - } Wu - //Specific factory class About classAfactoryImplementsfactory{ $ - @Override - PublicCPU createcpu () { - return NewCpua (); A } + the @Override - Publicmainboard Createmainboard () { $ return NewMainboarda (); the } the the } the - classBfactoryImplementsfactory{ in the @Override the PublicCPU createcpu () { About return Newcpub (); the } the the @Override + Publicmainboard Createmainboard () { - return NewMainboardb (); the }Bayi the}
Abstract Factory mode