<commit_before>---
layout: article
title: Abstract Factory Pattern C# Example
modified:
categories: 
excerpt: 
tags: []
image:
  feature: 
  teaser:
  thumb:
---

<a href="{{ site.url }}/creational/abstractFactory" class="btn"> <i class="fa fa-arrow-left" aria-hidden="true"></i> Return to Abstract Factory Pattern</a>

![State Pattern Structure](http://www.dofactory.com/images/diagrams/net/abstract.gif)

To set-up this example,  ASP.NET core is used create a Console Application. The full <a href="https://github.com/2joephillips/DPatterns-Examples/tree/master/creational/abstractFactory/csharp" target="_blank">C Sharp Code Base</a> can be accessed from GitHub.

{% include toc.html %}

## Set-up
Within this application, <code>Main()</code>, is used to print out several commands and new up the type of 
pizza, provide a list of pizzas that each type has, and places an order for a specific type of pizza.  
For this example there are two types of pizza Chicago and New York style.

```csharp
using System;
using AbstractFactoryPattern.Contracts;
using AbstractFactoryPattern.Services;

namespace AbstractFactoryPattern
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome." + Environment.NewLine);
            IPizzaStore store = new ChicagoStylePizza();
            
            store.listPizzas();

            System.Console.WriteLine("What type of Chicago Style pizzas' do you have?"+ Environment.NewLine);

            Console.WriteLine("Can I order Deep Dish Pizza."+ Environment.NewLine);  
            IPizza pizza = store.orderPizza("Deep Dish");
            pizza.createPizza();
            
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine("Welcome."+ Environment.NewLine);
            IPizzaStore store1 = new NewYorkStylePizza();
            
            store.listPizzas();

            System.Console.WriteLine("What type of New York Style pizzas' do you have?"+ Environment.NewLine);
            
            Console.WriteLine("Can I order Deep Hand Tossed."+ Environment.NewLine);
            IPizza pizza2 = store.orderPizza("HandTossed");
            pizza.createPizza();
        }
    }
}
```<commit_msg>added Set-up<commit_after>---
layout: article
title: Abstract Factory Pattern C# Example
modified:
categories: 
excerpt: 
tags: []
image:
  feature: 
  teaser:
  thumb:
---

<a href="{{ site.url }}/creational/abstractFactory" class="btn"> <i class="fa fa-arrow-left" aria-hidden="true"></i> Return to Abstract Factory Pattern</a>

![State Pattern Structure](http://www.dofactory.com/images/diagrams/net/abstract.gif)

To set-up this example,  ASP.NET core is used create a Console Application. The full <a href="https://github.com/2joephillips/DPatterns-Examples/tree/master/creational/abstractFactory/csharp" target="_blank">C Sharp Code Base</a> can be accessed from GitHub.

{% include toc.html %}

## Set-up
Within this application, <code>Main()</code>, is used to print out several commands and new up the type of 
pizza, provide a list of pizzas that each type has, and places an order for a specific type of pizza.  
For this example there are two types of pizza Chicago and New York style. These types are our Concrete Factories for our Abstract Factory IPizzaStore.
Each Concrete Factory is able to create a concrete Product/pizza from our IPizza Abstract Product class.

To help in organization I have used two folders to organize the code. Our Interfaces used for abstraction are within an Contracts folder giving it the namespace
AbstractFactoryPattern.Contracts, and the concrete classes are in AbstractFactoryPattern.Services.

```csharp
using System;
using AbstractFactoryPattern.Contracts;
using AbstractFactoryPattern.Services;

namespace AbstractFactoryPattern
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome." + Environment.NewLine);
            IPizzaStore store = new ChicagoStylePizza();
            
            store.listPizzas();

            System.Console.WriteLine("What type of Chicago Style pizzas' do you have?"+ Environment.NewLine);

            Console.WriteLine("Can I order Deep Dish Pizza."+ Environment.NewLine);  
            IPizza pizza = store.orderPizza("Deep Dish");
            pizza.createPizza();
            
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine("Welcome."+ Environment.NewLine);
            IPizzaStore store1 = new NewYorkStylePizza();
            
            store.listPizzas();

            System.Console.WriteLine("What type of New York Style pizzas' do you have?"+ Environment.NewLine);
            
            Console.WriteLine("Can I order Deep Hand Tossed."+ Environment.NewLine);
            IPizza pizza2 = store.orderPizza("HandTossed");
            pizza.createPizza();
        }
    }
}
```

## Abstract Factory

## Concrete Factory

## Abstract Product

## Product
{'fraction_non_alphanumeric': 0.09939227602430896, 'fraction_numerical': 0.001176239952950402, 'mean_word_length': 3.049206349206349, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '348934', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1338, 'n_words': 450}