Abstract factory

main
syneffort 2 years ago
parent 6d776fd755
commit ca0d1a5d2e
  1. 10
      DesignPatternGuru/AbstractFactory/AbstractFactory.csproj
  2. 32
      DesignPatternGuru/AbstractFactory/Client.cs
  3. 24
      DesignPatternGuru/AbstractFactory/Factories/ConcreteFactory1.cs
  4. 24
      DesignPatternGuru/AbstractFactory/Factories/ConcreteFactory2.cs
  5. 15
      DesignPatternGuru/AbstractFactory/Factories/IAbstractFactory.cs
  6. 16
      DesignPatternGuru/AbstractFactory/Products/ConcreteProductA1.cs
  7. 16
      DesignPatternGuru/AbstractFactory/Products/ConcreteProductA2.cs
  8. 23
      DesignPatternGuru/AbstractFactory/Products/ConcreteProductB1.cs
  9. 23
      DesignPatternGuru/AbstractFactory/Products/ConcreteProductB2.cs
  10. 13
      DesignPatternGuru/AbstractFactory/Products/IAbstractProductA.cs
  11. 14
      DesignPatternGuru/AbstractFactory/Products/IAbstractProductB.cs
  12. 10
      DesignPatternGuru/AbstractFactory/Program.cs
  13. 6
      DesignPatternGuru/DesignPatternGuru.sln

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,32 @@
using AbstractFactory.Factories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractFactory
{
internal class Client
{
public void Main()
{
Console.WriteLine("Client: Testring client code with the first factory type...");
ClientMethod(new ConcreteFactory1());
Console.WriteLine("---");
Console.WriteLine("Client: Testring client code with the second factory type...");
ClientMethod(new ConcreteFactory2());
}
private void ClientMethod(IAbstractFactory factory)
{
var ProductA = factory.CreateProductA();
var ProductB = factory.CreateProductB();
Console.WriteLine(ProductB.UsefulFuctionB());
Console.WriteLine(ProductB.AnotherUsefulFunctionB(ProductA));
}
}
}

@ -0,0 +1,24 @@
using AbstractFactory.Products;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractFactory.Factories
{
internal class ConcreteFactory1 : IAbstractFactory
{
public IAbstractProductA CreateProductA()
{
return new ConcreteProductA1();
}
public IAbstractProductB CreateProductB()
{
return new ConcreteProductB1();
}
}
}

@ -0,0 +1,24 @@
using AbstractFactory.Products;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractFactory.Factories
{
internal class ConcreteFactory2 : IAbstractFactory
{
public IAbstractProductA CreateProductA()
{
return new ConcreteProductA2();
}
public IAbstractProductB CreateProductB()
{
return new ConcreteProductB2();
}
}
}

@ -0,0 +1,15 @@
using AbstractFactory.Products;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractFactory.Factories
{
internal interface IAbstractFactory
{
IAbstractProductA CreateProductA();
IAbstractProductB CreateProductB();
}
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractFactory.Products
{
internal class ConcreteProductA1 : IAbstractProductA
{
public string UsefulFunctionA()
{
return "The result of the product A1.";
}
}
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractFactory.Products
{
internal class ConcreteProductA2 : IAbstractProductA
{
public string UsefulFunctionA()
{
return "The result of the product A2.";
}
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractFactory.Products
{
internal class ConcreteProductB1 : IAbstractProductB
{
public string AnotherUsefulFunctionB(IAbstractProductA collaborator)
{
var result = collaborator.UsefulFunctionA();
return $"The result of the B1 collaborating with the ({result})";
}
public string UsefulFuctionB()
{
return "The result of the product B1.";
}
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractFactory.Products
{
internal class ConcreteProductB2 : IAbstractProductB
{
public string AnotherUsefulFunctionB(IAbstractProductA collaborator)
{
var result = collaborator.UsefulFunctionA();
return $"The result of the B2 collaborating with the ({result})";
}
public string UsefulFuctionB()
{
return "The result of the product B2.";
}
}
}

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractFactory.Products
{
internal interface IAbstractProductA
{
string UsefulFunctionA();
}
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractFactory.Products
{
internal interface IAbstractProductB
{
string UsefulFuctionB();
string AnotherUsefulFunctionB(IAbstractProductA collaborator);
}
}

@ -0,0 +1,10 @@
namespace AbstractFactory
{
internal class Program
{
static void Main(string[] args)
{
new Client().Main();
}
}
}

@ -5,6 +5,8 @@ VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryMethod", "FactoryMethod\FactoryMethod.csproj", "{4F58C486-7121-435B-B7B2-F3ADD0FBE2AE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFactory", "AbstractFactory\AbstractFactory.csproj", "{8310590F-E10F-4845-8737-AF3CEF4583B1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{4F58C486-7121-435B-B7B2-F3ADD0FBE2AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F58C486-7121-435B-B7B2-F3ADD0FBE2AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F58C486-7121-435B-B7B2-F3ADD0FBE2AE}.Release|Any CPU.Build.0 = Release|Any CPU
{8310590F-E10F-4845-8737-AF3CEF4583B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8310590F-E10F-4845-8737-AF3CEF4583B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8310590F-E10F-4845-8737-AF3CEF4583B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8310590F-E10F-4845-8737-AF3CEF4583B1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save