Skip to content

Commit 1ea90ca

Browse files
committed
Worked With More DesignPatterns
1 parent dc2642c commit 1ea90ca

25 files changed

+563
-3
lines changed

AbstractFactory/Factory/IphoneFactoryPh.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class IphoneFactoryPh : IPhoneFactory
1111
{
1212
public IPhone CreatePhone(string model, string battery)
1313
{
14-
return new IPhone("xr","500mah");
14+
return IPhone("xr","500mah");
1515
}
1616
}
1717
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using BridgeDesignPattern.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 BridgeDesignPattern.Abstract
9+
{
10+
public class Abstraction
11+
{
12+
IBridge _bridge;
13+
public Abstraction(IBridge bridge)
14+
{
15+
_bridge = bridge;
16+
}
17+
18+
public string Operation()
19+
{
20+
return _bridge.Operation();
21+
}
22+
}
23+
}

BridgeDesignPattern/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,57 @@
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>{EB550418-5560-46E4-9F3A-95B96F734B47}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>BridgeDesignPattern</RootNamespace>
10+
<AssemblyName>BridgeDesignPattern</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="Abstract\Abstraction.cs" />
47+
<Compile Include="Concrete\ImplementationA.cs" />
48+
<Compile Include="Concrete\ImplementationB.cs" />
49+
<Compile Include="Interface\IBridge.cs" />
50+
<Compile Include="Program.cs" />
51+
<Compile Include="Properties\AssemblyInfo.cs" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<None Include="App.config" />
55+
</ItemGroup>
56+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
57+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using BridgeDesignPattern.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 BridgeDesignPattern.Concrete
9+
{
10+
class ImplementationA : IBridge
11+
{
12+
public string Operation()
13+
{
14+
return "Implementation A";
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using BridgeDesignPattern.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 BridgeDesignPattern.Concrete
9+
{
10+
class ImplementationB : IBridge
11+
{
12+
public string Operation()
13+
{
14+
return "Implementation B";
15+
}
16+
}
17+
}
+13
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 BridgeDesignPattern.Interface
8+
{
9+
public interface IBridge
10+
{
11+
string Operation();
12+
}
13+
}

BridgeDesignPattern/Program.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using BridgeDesignPattern.Abstract;
2+
using BridgeDesignPattern.Concrete;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace BridgeDesignPattern
10+
{
11+
class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
Abstraction abstractionA = new Abstraction(new ImplementationA());
16+
Abstraction abstractionB = new Abstraction(new ImplementationB());
17+
18+
Console.WriteLine(abstractionA.Operation());
19+
Console.WriteLine(abstractionB.Operation());
20+
Console.ReadKey();
21+
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("BridgeDesignPattern")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("BridgeDesignPattern")]
13+
[assembly: AssemblyCopyright("Copyright © 2021")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("eb550418-5560-46e4-9f3a-95b96f734b47")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

DecoratorDesignPattern/Decorators/Decorator.cs renamed to DecoratorDesignPattern/Abstract/Decorator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace DecoratorDesignPattern.Decorators
99
{
10-
public class Decorator : IShape
10+
public abstract class Decorator : IShape
1111
{
1212
readonly IShape _shape=null;
1313
public Decorator(IShape shape)

DecoratorDesignPattern/DecoratorDesignPattern.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<Compile Include="ConcreteDecorator\CircleEdge.cs" />
4747
<Compile Include="Concrete\Circle.cs" />
4848
<Compile Include="ConcreteDecorator\CircleFill.cs" />
49-
<Compile Include="Decorators\Decorator.cs" />
49+
<Compile Include="Abstract\Decorator.cs" />
5050
<Compile Include="Interface\IShape.cs" />
5151
<Compile Include="Program.cs" />
5252
<Compile Include="Properties\AssemblyInfo.cs" />

DesignPatterns.sln

+14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DecoratorDesignPattern", "D
2121
EndProject
2222
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObserverDesignPattern", "ObserverDesignPattern\ObserverDesignPattern.csproj", "{8101A348-BD6B-4726-BFDA-37AEB8989ECA}"
2323
EndProject
24+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BridgeDesignPattern", "BridgeDesignPattern\BridgeDesignPattern.csproj", "{EB550418-5560-46E4-9F3A-95B96F734B47}"
25+
EndProject
26+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediatorDesignPattern", "MediatorDesignPattern\MediatorDesignPattern.csproj", "{A3D7E250-FFBD-44FF-B5F8-0C33606AA598}"
27+
EndProject
2428
Global
2529
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2630
Debug|Any CPU = Debug|Any CPU
@@ -51,6 +55,14 @@ Global
5155
{8101A348-BD6B-4726-BFDA-37AEB8989ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU
5256
{8101A348-BD6B-4726-BFDA-37AEB8989ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU
5357
{8101A348-BD6B-4726-BFDA-37AEB8989ECA}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{EB550418-5560-46E4-9F3A-95B96F734B47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59+
{EB550418-5560-46E4-9F3A-95B96F734B47}.Debug|Any CPU.Build.0 = Debug|Any CPU
60+
{EB550418-5560-46E4-9F3A-95B96F734B47}.Release|Any CPU.ActiveCfg = Release|Any CPU
61+
{EB550418-5560-46E4-9F3A-95B96F734B47}.Release|Any CPU.Build.0 = Release|Any CPU
62+
{A3D7E250-FFBD-44FF-B5F8-0C33606AA598}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63+
{A3D7E250-FFBD-44FF-B5F8-0C33606AA598}.Debug|Any CPU.Build.0 = Debug|Any CPU
64+
{A3D7E250-FFBD-44FF-B5F8-0C33606AA598}.Release|Any CPU.ActiveCfg = Release|Any CPU
65+
{A3D7E250-FFBD-44FF-B5F8-0C33606AA598}.Release|Any CPU.Build.0 = Release|Any CPU
5466
EndGlobalSection
5567
GlobalSection(SolutionProperties) = preSolution
5668
HideSolutionNode = FALSE
@@ -62,6 +74,8 @@ Global
6274
{23D7FCBB-8903-4A54-89FC-DC3B7CA9452B} = {BBB07D4C-2053-41CE-8992-71C11CFA5AC8}
6375
{968AC08B-1819-43AC-B779-7E1C407867D0} = {BC5AE366-983C-408E-8C1E-253905F87C60}
6476
{8101A348-BD6B-4726-BFDA-37AEB8989ECA} = {78AB65D7-727C-47CD-99E4-8A0A922B6550}
77+
{EB550418-5560-46E4-9F3A-95B96F734B47} = {BC5AE366-983C-408E-8C1E-253905F87C60}
78+
{A3D7E250-FFBD-44FF-B5F8-0C33606AA598} = {78AB65D7-727C-47CD-99E4-8A0A922B6550}
6579
EndGlobalSection
6680
GlobalSection(ExtensibilityGlobals) = postSolution
6781
SolutionGuid = {04EE2CDC-F0CA-4892-988E-EDBEA09EDFDC}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using MediatorDesignPattern.Concrete;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace MediatorDesignPattern.Abstract
9+
{
10+
public class BaseUser
11+
{
12+
public string Name { get; set; }
13+
public ConcreteMediator concreteMediator { set; get; }
14+
public BaseUser(string name)
15+
{
16+
this.Name = name;
17+
}
18+
public void SendMessage(string receiver,string messsage)
19+
{
20+
concreteMediator.SendMessage(Name, receiver, messsage);
21+
}
22+
public virtual void MessageReceiver(string sender, string messsage)
23+
{
24+
Console.WriteLine("{0} to {1}: '{2}'", sender, Name, messsage);
25+
}
26+
}
27+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace MediatorDesignPattern.Abstract
8+
{
9+
public abstract class Mediator
10+
{
11+
public abstract void SignIn(BaseUser baseUser);
12+
13+
public abstract void SendMessage(string sebder, string receiver, string message);
14+
}
15+
}

MediatorDesignPattern/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,28 @@
1+
using MediatorDesignPattern.Abstract;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace MediatorDesignPattern.Concrete
9+
{
10+
public class ConcreteMediator : Mediator
11+
{
12+
private Dictionary<string, BaseUser> _baseUsers = new Dictionary<string, BaseUser>();
13+
public override void SendMessage(string sender, string receiver, string message)
14+
{
15+
BaseUser baseUser = _baseUsers[receiver];
16+
throw new NotImplementedException();
17+
}
18+
19+
public override void SignIn(BaseUser baseUser)
20+
{
21+
if (!_baseUsers.ContainsValue(baseUser))
22+
{
23+
_baseUsers[baseUser.Name] = baseUser;
24+
}
25+
baseUser.concreteMediator = this;
26+
}
27+
}
28+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using MediatorDesignPattern.Abstract;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace MediatorDesignPattern.Concrete
9+
{
10+
public class User1 : BaseUser
11+
{
12+
public User1(string name) : base(name)
13+
{
14+
15+
}
16+
public override void MessageReceiver(string sender, string messsage)
17+
{
18+
Console.WriteLine("From : User1: ");
19+
base.MessageReceiver(sender, messsage);
20+
}
21+
}
22+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using MediatorDesignPattern.Abstract;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace MediatorDesignPattern.Concrete
9+
{
10+
public class User2 : BaseUser
11+
{
12+
public User2(string name) : base(name)
13+
{
14+
15+
}
16+
public override void MessageReceiver(string sender, string messsage)
17+
{
18+
Console.WriteLine("From : User2: ");
19+
base.MessageReceiver(sender, messsage);
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)