Factory Pattern.` A factory creates objects. We implement the factory design pattern in a C# program. With this pattern, we develop an abstraction that isolates the logic for determining which type of class to create. `Object `object`Example.` The factory design pattern relies on a type hierarchy. The classes must all implement an interface or derive from a base class. We use an abstract class as the base. The Manager, Clerk and Programmer classes derive from Position. `Interface `interface`Abstract `abstract`The factory design pattern` is found in the Factory class. The point of the Get method is to take a value and instantiate a class based on that value. It translates integers to objects with a switch statement. `Switch `switch`Because Manager, Clerk, and Programmer all derive from the same abstract class, the return type Position can be used.`An implicit cast automatically casts the Manager, Clerk and Programmer to Position references.`The Main method` serves to demonstrate the Factory class in action. We use as part of the demonstration the integers 0, 1, 2, and 3. We use the Get method with each of these values. `Then: `We show that the appropriate type of class was instantiated for each integer.`Discussion.` Imagine you have a system that needs to create objects in many different places. Suppose the system has integers and you want objects for those integers. The factory pattern is ideal for this usage. `You can use the Factory type to handle object creation in a uniform and concise way.`Summary.` We looked the factory design pattern, which is used to instantiate objects based on another data type such as integers. Factories can be used to reduce code bloat and also make it easier to modify which objects need to be created.

EAOIRFactory pattern eAF: C#ROOADAQAbAJAAO{OEabstract AJPositionOE{OEEABabstract AP Title { get; }OE}OOEAJManager : PositionOE{OEEABoverride AP TitleOEE{OEEEgetOEEE{OEEEEAK IManagerI;OEEE}OEE}OE}OOEAJClerk : PositionOE{OEEABoverride AP TitleOEE{OEEEgetOEEE{OEEEEAK IClerkI;OEEE}OEE}OE}OOEAJAAmer : PositionOE{OEEABoverride AP TitleOEE{OEEEgetOEEE{OEEEEAK IAAmerI;OEEE}OEE}OE}OOEA?AJFactoryOE{ROEE/A{<A7>OEE/A{Decides which AJto instantiate.OEE/A{</A7>OEERABA?Position Get(Aiid)OEE{OEEEAH (id)OEEE{OEEEEAf0:OEEEEEAK AqManager();OEEEEAf1:OEEEEAf2:OEEEEEAK AqClerk();OEEEEAf3:OEEEEdefault:OEEEEEAK AqAAmer();OEEE}OEE}OE}OOEA%E{OEEAw(AiiAy0; i <= 3; i++)OEE{OEEEvar positionAyFactory.Get(i);OEEEA'IWhere idAy{0}, positionAy{1} I, i, position.Title);OEE}OE}O}OOROOWhere idAy0, positionAyManagerOWhere idAy1, positionAyClerkOWhere idAy2, positionAyClerkOWhere idAy3, positionAyAAmerR