*   >> lukeminen koulutus Artikkelit >> science >> programming

Abstrakti tehdassuunnitteluryhmä Pattern

kissa. 6. Se tekee vaihtamalla tuoteperheiden helppoa. 7. Se edistää johdonmukaisuutta tuotteiden kesken. 8. Se tukee uusia erilaisia ​​tuotteita ja niiden familiesExample: julkisen liittymän IComputerFactory {ICPU createCPU (); IMemory createMemory ();} julkisen liittymän ICPU {string GetCPUString ();} julkisen liittymän IMemory {string GetMemoryString ();} //Betoni CPUApublic luokka CPUA: n: ICPU {public String GetCPUString () {return "CPUA: n"; }} //Betoni MemoryApublic luokka MemoryA: IMemory {public String GetMemoryString () {return "MemoryA"; }} Public class ComputerFactoryA: IComputerFactory {julkinen ICPU createCPU () {palata uusi CPUA: n (); } Julkinen IMemory createMemory () {palata uusi MemoryA (); }} Public class Client {//tämä on malli menetelmä; ei riipu betonitehtaalla //ja Betoni luokat julkinen staattinen merkkijono BuildComputer (IComputerFactory tehdas) {ICPU cpu = factory.

createCPU (); IMemory muisti = factory.createMemory (); StringBuilder sb = uusi StringBuilder (); sb.Append (string.Format ("CPU: {0}", cpu.GetCPUString ())); sb.Append (Environment.NewLine); sb.Append (string.Format ("Memory: {0}", memory.GetMemoryString ())); palata sb.ToString ();}} Calling Clientprivate mitätöidä button2_Click (objekti lähettäjän EventArgs e) {Abstract_Factory.IComputerFactory tehdas = uusi Abstract_Factory.ComputerFactoryA();MessageBox.Show(Abstract_Factory.Client.BuildComputer(factory));}

Page   <<  [1] [2] 
Copyright © 2008 - 2016 lukeminen koulutus Artikkelit,https://koulutus.nmjjxx.com All rights reserved.