Since it is necessary to mention the factory model, we need to mention simple factories.
Simple Factory mode: is the creation mode of a class, or it can be called a static factory.
Can be understood so.
A factory can produce a category of products that must belong to the category. Just as the aircraft belongs to the aircraft and the eggs are not the same class.
Now take the aircraft as an example
Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading;namespace Consoleapplication1{class Program {static void Main (string[] args) {Aircraft A = Aircraf Tfactory.create (1); A.fly (); A.inventor (); }} public interface aircraft {void Fly ();//aircraft characteristics, to fly void Inventor ();//inventors, may have a brand or something will not write} public class Airplane:aircraft {public void Fly () {Console.WriteLine ("I am flying in the sky"); } public void Inventor () {Console.WriteLine ("Earth Man"); }} public class Ufo:aircraft {public void Fly () {Console.WriteLine ("I am flying in space"); } public void Inventor () {Console.WriteLine ("Alien"); }} public class Aircraftfactory {public static aircraft create (int ") {if (what = 1) return new AiRplane (); else if (what = = 2) return new UFO (); else return null; } }}
For example: The subtraction of a calculator can use this mode
The bitter force also chats the pattern--(1)--Simple factory