---
title: "Factory Method Design Pattern using C#"  
description: "Factory Method Design Pattern using C#"  
author: "Anonymous User"  
published: 2016-03-04  
updated: 2016-03-04  
canonical: https://www.mindstick.com/forum/34032/factory-method-design-pattern-using-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Factory Method Design Pattern using C#

We want to use [Factory](https://www.mindstick.com/blog/304231/factory-vs-service-in-angularjs-which-one-better) [Method](https://www.mindstick.com/forum/166/webservice-method) [Design Pattern](https://www.mindstick.com/forum/33927/how-to-implement-singleton-design-pattern-in-c-sharp) in c#. How will do this please help me.

## Replies

### Reply by Anonymous User

In [class-based programming](https://en.wikipedia.org/wiki/Class-based_programming), the **factory method pattern** is a [creational pattern](https://en.wikipedia.org/wiki/Creational_pattern) that uses factory methods to deal with the problem of [creating objects](https://en.wikipedia.org/wiki/Object_creation) without having to specify the exact [class](https://en.wikipedia.org/wiki/Class_(computer_programming)) of the object that will be created. This is done by creating objects by calling a factory method—either specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived classes—rather than by calling a [constructor](https://en.wikipedia.org/wiki/Constructor_(object-oriented_programming)).

```
using System;
using System.Linq;
namespace ConsoleDemo
{
    public class Program
    {
        static void Main()
        {
            Factory[] objFactories = new Factory[2];
            objFactories[0] = new concreteFactoryforEmployee();
            objFactories[1] = new concreteFactoryforFounder();
            foreach (Factory objFactory in objFactories)
            {
                DetailsMaster objProduct = objFactory.GetDetails();
                objProduct.GetDetails();
            }
            Console.ReadLine();
        }

    }

　
    abstract class Factory
    {
        public abstract DetailsMaster GetDetails(); //Factory Method Declaration
    }

    class concreteFactoryforEmployee : Factory
    {
        public override DetailsMaster GetDetails() //Factory Method Implementation
        {
            return new Employee();
        }
    }

    class concreteFactoryforFounder : Factory
    {
        public override DetailsMaster GetDetails() //Factory Method Implementation
        {
            return new Founder();
        }
    }

    interface DetailsMaster
    {
        void GetDetails();
    }

    class Employee : DetailsMaster
    {
        public void GetDetails()
        {
            Console.WriteLine("Emplyee Details");
            Console.WriteLine("======================================");
            Console.WriteLine("Name : Rahul");
            Console.WriteLine("Join Date : 03/03/206");
            Console.WriteLine("designation : Software Developer");
            Console.WriteLine("======================================");
        }
    }

    class Founder : DetailsMaster
    {
        public void GetDetails()
        {
            Console.WriteLine("Company Details");
            Console.WriteLine("======================================");
            Console.WriteLine("Name : Jan Singh");
            Console.WriteLine("Company Name : ItechWays");
        }
    }

}
```

![Factory Method Design Pattern using C#](https://www.mindstick.com/mindstickforums/8642f97b-b20b-4cb0-98d0-fb6d9ea28767/images/64ffed0c-7fd1-4d7e-9544-eb37de6c5fe8.png)


---

Original Source: https://www.mindstick.com/forum/34032/factory-method-design-pattern-using-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
