Skip to content

Commit b28b62b

Browse files
author
Hasan ALTAN
committed
3 patterns added
1 parent 0e56f75 commit b28b62b

34 files changed

+704
-2
lines changed

DecoratorPattern/DecoratorPattern.csproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
<ItemGroup>
6060
<None Include="App.config" />
6161
</ItemGroup>
62-
<ItemGroup />
62+
<ItemGroup>
63+
<Content Include="TextFile1.txt" />
64+
</ItemGroup>
6365
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6466
</Project>

DecoratorPattern/TextFile1.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Decorator Pattern
2+
3+
This pattern interest with structural of object.Moreover,"Decorator Pattern" belongs to Structural Categories.
4+
For instance;
5+
Just think about a coffeeshop;
6+
when you go to Coffeeshop u want to a coffee and teller says u " Would u want to milk" and " Would u want to sugar" then i assume u say yes.Teller adds them to your coffer.As a conclusion,Did it change your coffer orginially? i mean it didn't change ur coffee to coke.It is coffee but teller added milk and sugar.This pattern same logic.

DesignPatterns.sln

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainOfResponsibilityPatter
1313
EndProject
1414
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DecoratorPattern", "DecoratorPattern\DecoratorPattern.csproj", "{5811DDBE-773C-48D8-BBC3-29B0D7A5C9A9}"
1515
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObserverPattern", "ObserverPattern\ObserverPattern.csproj", "{8F094A80-BFBA-4CCE-B5CB-DD3E62EE53BC}"
17+
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FactoryMethodPattern", "FactoryMethodPattern\FactoryMethodPattern.csproj", "{C560D63D-E230-4463-8E41-82E4C1EE503A}"
19+
EndProject
1620
Global
1721
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1822
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +43,14 @@ Global
3943
{5811DDBE-773C-48D8-BBC3-29B0D7A5C9A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
4044
{5811DDBE-773C-48D8-BBC3-29B0D7A5C9A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
4145
{5811DDBE-773C-48D8-BBC3-29B0D7A5C9A9}.Release|Any CPU.Build.0 = Release|Any CPU
46+
{8F094A80-BFBA-4CCE-B5CB-DD3E62EE53BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47+
{8F094A80-BFBA-4CCE-B5CB-DD3E62EE53BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
48+
{8F094A80-BFBA-4CCE-B5CB-DD3E62EE53BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
49+
{8F094A80-BFBA-4CCE-B5CB-DD3E62EE53BC}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{C560D63D-E230-4463-8E41-82E4C1EE503A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{C560D63D-E230-4463-8E41-82E4C1EE503A}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{C560D63D-E230-4463-8E41-82E4C1EE503A}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{C560D63D-E230-4463-8E41-82E4C1EE503A}.Release|Any CPU.Build.0 = Release|Any CPU
4254
EndGlobalSection
4355
GlobalSection(SolutionProperties) = preSolution
4456
HideSolutionNode = FALSE

DesignPatterns/DependencyInjection.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,5 @@
8282
<ItemGroup>
8383
<None Include="App.config" />
8484
</ItemGroup>
85-
<ItemGroup />
8685
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8786
</Project>

FactoryMethodPattern/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{C560D63D-E230-4463-8E41-82E4C1EE503A}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>FactoryMethodPattern</RootNamespace>
10+
<AssemblyName>FactoryMethodPattern</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Net.Http" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="Part1\Concrete\DefaultProduct.cs" />
47+
<Compile Include="Part1\Concrete\Product_A.cs" />
48+
<Compile Include="Part1\Concrete\Product_B.cs" />
49+
<Compile Include="Part1\Creator\ProductCreator.cs" />
50+
<Compile Include="Part1\Interface\IProduct.cs" />
51+
<Compile Include="Part2\Concrete\PLSLoggerFactory.cs" />
52+
<Compile Include="Part2\Concrete\PLSLogger.cs" />
53+
<Compile Include="Part2\Concrete\SystemLogger.cs" />
54+
<Compile Include="Part2\Concrete\SystemLoggerFactory.cs" />
55+
<Compile Include="Part2\Creator\SystemManager.cs" />
56+
<Compile Include="Part2\Interface\ILogger.cs" />
57+
<Compile Include="Part2\Interface\ILoggerFactory.cs" />
58+
<Compile Include="Program.cs" />
59+
<Compile Include="Properties\AssemblyInfo.cs" />
60+
</ItemGroup>
61+
<ItemGroup>
62+
<None Include="App.config" />
63+
</ItemGroup>
64+
<ItemGroup>
65+
<Content Include="Theorical.txt" />
66+
</ItemGroup>
67+
<ItemGroup />
68+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
69+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using FactoryMethodPattern.Part1.Interface;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace FactoryMethodPattern.Part1.Concrete
9+
{
10+
public class DefaultProduct : IProduct
11+
12+
{
13+
public string ShipFrom()
14+
{
15+
return "not avaliable";
16+
}
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using FactoryMethodPattern.Part1.Interface;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace FactoryMethodPattern.Part1.Concrete
9+
{
10+
public class Product_A : IProduct
11+
{
12+
public string ShipFrom()
13+
{
14+
return "South Africa";
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using FactoryMethodPattern.Part1.Interface;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace FactoryMethodPattern.Part1.Concrete
9+
{
10+
public class Product_B : IProduct
11+
{
12+
13+
public string ShipFrom()=>"from Columbia" ;
14+
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using FactoryMethodPattern.Part1.Concrete;
2+
using FactoryMethodPattern.Part1.Interface;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace FactoryMethodPattern.Part1.Creator
10+
{
11+
public class ProductCreator:IProduct
12+
{
13+
public IProduct FactoryMethod(int month)
14+
{
15+
if (month >= 4 && month <= 11)
16+
{
17+
return new Product_A();
18+
}
19+
else if {(month ==1 || month ==2 || month == 3 )
20+
{
21+
return new Product_B();
22+
23+
}
24+
25+
}
26+
else
27+
{
28+
return new DefaultProduct();
29+
}
30+
}
31+
32+
public string ShipFrom()
33+
{
34+
throw new NotImplementedException();
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace FactoryMethodPattern.Part1.Interface
8+
{
9+
public interface IProduct
10+
{
11+
string ShipFrom();
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using FactoryMethodPattern.Part2.Interface;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace FactoryMethodPattern.Part2.Concrete
9+
{
10+
public class PLSLogger : ILogger
11+
{
12+
public void Log()
13+
{
14+
Console.WriteLine("Motors PLS was logged..!");
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using FactoryMethodPattern.Part2.Interface;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace FactoryMethodPattern.Part2.Concrete
9+
{
10+
public class PLSLoggerFactory : ILoggerFactory
11+
{
12+
public ILogger CreateLogger()
13+
{
14+
return new PLSLogger();
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using FactoryMethodPattern.Part2.Interface;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace FactoryMethodPattern.Part2.Concrete
9+
{
10+
public class SystemLogger : ILogger
11+
{
12+
public void Log()
13+
{
14+
Console.WriteLine("System log was logged..");
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using FactoryMethodPattern.Part2.Interface;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace FactoryMethodPattern.Part2.Concrete
9+
{
10+
public class SystemLoggerFactory : ILoggerFactory
11+
{
12+
public ILogger createLogger()
13+
{
14+
new SystemLogger();
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using FactoryMethodPattern.Part2.Concrete;
2+
using FactoryMethodPattern.Part2.Interface;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace FactoryMethodPattern.Part2.Creator
10+
{
11+
public class SystemManager
12+
{
13+
private ILoggerFactory _loggerFactory;
14+
15+
public SystemManager(ILoggerFactory loggerFactory) => _loggerFactory = loggerFactory;
16+
17+
public void Save()
18+
{
19+
ILogger loggerSystem = new SystemLoggerFactory().CreateLogger();
20+
ILogger loggerPLS = new PLSLoggerFactory().CreateLogger();
21+
loggerSystem.Log();
22+
loggerPLS.Log();
23+
}
24+
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace FactoryMethodPattern.Part2.Interface
8+
{
9+
public interface ILogger
10+
{
11+
void Log();
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace FactoryMethodPattern.Part2.Interface
8+
{
9+
public interface ILoggerFactory
10+
{
11+
ILogger CreateLogger();
12+
13+
}
14+
}

FactoryMethodPattern/Program.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using FactoryMethodPattern.Part1.Creator;
2+
using FactoryMethodPattern.Part1.Interface;
3+
using FactoryMethodPattern.Part2.Concrete;
4+
using FactoryMethodPattern.Part2.Creator;
5+
using System;
6+
7+
8+
namespace FactoryMethodPattern
9+
{
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
15+
#region Part1
16+
ProductCreator c = new ProductCreator();
17+
IProduct product;
18+
for (int month = 1; month < 12; month++)
19+
{
20+
product = c.FactoryMethod(month);
21+
Console.WriteLine("Coffee Beanssh" + product.ShipFrom());
22+
}
23+
#endregion
24+
#region Part2
25+
SystemManager systemManager = new SystemManager(new SystemLoggerFactory());
26+
systemManager.Save();
27+
#endregion
28+
29+
Console.ReadKey();
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)