Skip to content

Commit 8d0ab3b

Browse files
committed
Add project files.
1 parent a510a9a commit 8d0ab3b

File tree

7 files changed

+141
-0
lines changed

7 files changed

+141
-0
lines changed

DesignPatterns.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

DesignPatterns.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32825.248
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPatterns", "DesignPatterns.csproj", "{884C2FD3-F204-4DE2-B246-C0843039D7D9}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{884C2FD3-F204-4DE2-B246-C0843039D7D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{884C2FD3-F204-4DE2-B246-C0843039D7D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{884C2FD3-F204-4DE2-B246-C0843039D7D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{884C2FD3-F204-4DE2-B246-C0843039D7D9}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {26F319F6-0A76-4330-934F-660C59AB743F}
24+
EndGlobalSection
25+
EndGlobal

IProduct.cs

Lines changed: 14 additions & 0 deletions
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 DesignPatterns
8+
{
9+
public interface IProduct
10+
{
11+
string GetUsername(string emailAddress);
12+
}
13+
14+
}

Product.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace DesignPatterns
8+
{
9+
public class Product : IProduct
10+
{
11+
public string GetUsername(string emailAddress)
12+
{
13+
int atIndex = emailAddress.IndexOf('@');
14+
return (atIndex > 0) ? emailAddress.Substring(0, atIndex) : string.Empty;
15+
}
16+
}
17+
18+
}

ProductFactory.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace DesignPatterns
8+
{
9+
public class ProductFactory
10+
{
11+
public IProduct CreateProduct()
12+
{
13+
return new Product();
14+
}
15+
}
16+
17+
}

Program.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using DesignPatterns;
2+
3+
//No Pattern
4+
Console.WriteLine("No Pattern");
5+
Console.WriteLine($"Hello, {GetUsername("[email protected]")}!");
6+
7+
static string GetUsername(string emailAddress)
8+
{
9+
int atIndex = emailAddress.IndexOf('@');
10+
return (atIndex > 0) ? emailAddress.Substring(0, atIndex) : string.Empty;
11+
}
12+
13+
//Singleton Pattern
14+
Console.WriteLine("Singleton Pattern");
15+
Console.WriteLine($"Hello, {Singleton.Instance.GetUsername("[email protected]")}!");
16+
17+
//Factory Pattern
18+
ProductFactory factory = new ProductFactory();
19+
IProduct product = factory.CreateProduct();
20+
Console.WriteLine("Factory Pattern");
21+
Console.WriteLine($"Hello, {product.GetUsername("[email protected]")}!");

Singleton.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace DesignPatterns
8+
{
9+
public class Singleton
10+
{
11+
private static Singleton instance;
12+
13+
private Singleton()
14+
{
15+
// Private constructor to prevent instantiation from outside the class
16+
}
17+
18+
public static Singleton Instance
19+
{
20+
get
21+
{
22+
if (instance == null)
23+
{
24+
instance = new Singleton();
25+
}
26+
return instance;
27+
}
28+
}
29+
30+
public string GetUsername(string emailAddress)
31+
{
32+
int atIndex = emailAddress.IndexOf('@');
33+
return (atIndex > 0) ? emailAddress.Substring(0, atIndex) : string.Empty;
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)