1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespace_03 Simple Factory design mode8 {9 class ProgramTen { One Static voidMain (string[] args) A { -Console.WriteLine ("Please enter the notebook brand you want"); - stringBrand =console.readline (); theNoteBook NB =Getnotebook (brand); - nb. SayHello (); - Console.readkey (); - } + - + /// <summary> A ///the core of a simple factory assigns a value to the parent class based on the user's input at /// </summary> - /// <param name= "brand" ></param> - /// <returns></returns> - Public StaticNoteBook Getnotebook (stringbrand) - { -NoteBook NB =NULL; in Switch(Brand) - { to Case "Lenovo": NB =NewLenovo (); + Break; - Case "IBM": NB =NewIBM (); the Break; * Case "Acer": NB =NewAcer (); $ Break;Panax Notoginseng Case "Dell": NB =NewDell (); - Break; the } + returnnb; A } the } + - Public Abstract classNoteBook $ { $ Public Abstract voidSayHello (); - } - the Public classLenovo:notebook - {Wuyi Public Override voidSayHello () the { -Console.WriteLine ("I'm a Lenovo notebook, and you don't think about it."); Wu } - } About $ - Public classAcer:notebook - { - Public Override voidSayHello () A { +Console.WriteLine ("I am the Hongji notebook"); the } - } $ the Public classDell:notebook the { the Public Override voidSayHello () the { -Console.WriteLine ("I'm a Dell laptop ."); in } the } the About Public classIbm:notebook the { the Public Override voidSayHello () the { +Console.WriteLine ("I am an IBM notebook"); - } the }Bayi}
Simple Factory design mode