---------- Sample
------------------------------
Using
System;
Namespace
Factory
{/ ** ////
---------------------------
Using
System;
Namespace
Factory
{/ ** ////
------------------------------
Using
System;
Namespace
Factory
{/ ** ////
-------------------------------
System;
Namespace
Factory
{/ ** ////
--------------------------------
/ ** /
/// Simple Factory Mode Example //
Using
System;
Using
System.drawing;
Using
System.collections;
Using
System.componentmodel;
Using
System.windows.forms;
Using
System.data;
Namespace
Factory
{/ ** ////
/// summary> private vid initializecomponent () {this.label1 = new system.windows.forms.label (); this.txname = new system.windows.Forms.TextBox (); this.btcomputer = new system. Windows.Forms.Button (); this.label2 = new system.windows.forms.label (); this.label3 = new system.windows.forms.label (); this.txlname = new system.windows.Forms.TextBox (); This.txfname = new system.windows.Forms.TextBox (); this.label4 = new system.windows.forms.label (); this.suspendlayout (); // // label1 // this.label1. Location = new system.drawing.point (32, 112); this.label1.name = "label1"; this.label1.tabindex = 0; this.label1.text = "enter name"; // // txname // THIS.TXNAME.LOCATION = New System.drawing.point (168, 112); this.txname.name = "TXNAME"; this.txname.tabindex = 1; this.txname.text = ""; // BTComputer // this.btcomputer.location = new system.drawing.point (120, 248); this.btcomputer.name = "btcomputer"; this.btcomputer.tabindex = 2 "This.btcomputer.text =" computer "; this.btcomputer.click = new system.EventHandler (this.btcomputer_click; // // label2 // this.label2.location = new system.drawing.point (32, 160); this.label2.name = "label2"; this.label2.tabindex = 3; this.label2.text = "first name"; // // label3 // this.label3.Location = new system.drawing. Point (32, 200); this.label3.name = "label3"; this.label3.tabindex = 4; this.label3.text = "last name"; ////////////////////////////// // TXLName.Location =
New system.drawing.point (168, 200); this.txlname.name = "txlname"; this.txlname.tabindex = 5; this.txlname.text = ""; /// TXFNAME // this.txfname. Location = new system.drawing.point (168, 152); this.txfname.name = "TXFNAME"; this.txfname.tabindex = 6; this.txfname.text = ""; /// Label4 // this. Label4.font = new system.drawing.font ("Song", 20F, System.drawing.FontStyle.Regular, System.drawing.graphicsUnit.Point, ((System.byte) (134))); this.Label4.Location = New system.drawing.point (80, 32); this.label4.name = "label4"; this.label4.size = new system.drawing.size (208, 40); this.label4.tabindex = 7; this .label4.text = "Simple factory example"; // // Form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (368, 307); This.Controls.add (this.label4); this.controls.add (this.txfname); this.controls.add (this.txlname); this.controls.add (this.label3); this.controls.add ( This.label2); this.Controls. Add (THIS.BTComputer); this.controls.add (this.txname); this.controls.add (this.label1); this.name = "form1"; this.text = "form1"; this.Load = New system.eventhandler (this.form1_load); this.ResumeLayout (false);} #ENDREGION / ** ////
/// summary> [STAThread] static void Main () {Application.Run (new Form1 ());} private void Form1_Load (object sender, System.EventArgs e) {} private void btComputer_Click (object sender, System. Eventargs e) {namefactory nf = new namefactory (); NAMER NM = nf.getname (this.txname.text); this.txfname.text = nm.getfname (); this.txlname.text = nm.getlname (); }}} -------------------------- The last is the application of simple factory model. Simple factory model has more than three classes. One is a base class, more than one inheritance class and a factory class, and the last is of course an application class. The simple factory model is implemented with multiple inheritance, it can be said that it is applied to a number of solutions.