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.

456Factory pattern e5Q: C#6 5P5O5S5D5; { 4abstract 5DPosition 4{ 445=abstract 5L Title { get; } 4} 45DManager : Position 4{ 445=override 5L Title 44{5'get5'{5'45J "Manager";5'} 44} 4} 45DClerk : Position 4{ 445=override 5L Title 44{5'get5'{5'45J "Clerk";5'} 44} 4} 45D5;mer : Position 4{ 445=override 5L Title 44{5'get5'{5'45J "5;mer";5'} 44} 4} 45A5DFactory 4{6 44/5{<5B> 44/5{Decides which 5Dto instantiate. 44/5{</5B> 4465=5APosition Get(5sid) 44{5'5N (id)5'{5'45V0:5'445J 5wManager();5'45V1:5'45V2:5'445J 5wClerk();5'45V3:5'4default:5'445J 5w5;mer();5'} 44} 4} 45$4{ 445o(5si5z0; i <= 3; i++) 44{5'var position5zFactory.Get(i);5'5%"Where id5z{0}, position5z{1} ", i, position.Title); 44} 4} } 6 Where id5z0, position5zManager Where id5z1, position5zClerk Where id5z2, position5zClerk Where id5z3, position5z5;mer6