Skip to content

Commit 7c26dea

Browse files
committed
Add project files.
1 parent dc55f29 commit 7c26dea

File tree

106 files changed

+1632
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1632
-0
lines changed
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>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

AbstractFactory/CsvParser.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class CsvParser : ICsvParser
2+
{
3+
public void Parse(string input)
4+
{
5+
Console.WriteLine($"Parsing CSV: {input}");
6+
}
7+
}

AbstractFactory/ICsvParser.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public interface ICsvParser
2+
{
3+
void Parse(string input);
4+
}

AbstractFactory/IJsonParser.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public interface IJsonParser
2+
{
3+
void Parse(string input);
4+
}

AbstractFactory/IParserFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public interface IParserFactory
2+
{
3+
IJsonParser CreateJsonParser();
4+
IXmlParser CreateXmlParser();
5+
ICsvParser CreateCsvParser();
6+
}

AbstractFactory/IXmlParser.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public interface IXmlParser
2+
{
3+
void Parse(string input);
4+
}

AbstractFactory/JsonParser.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class JsonParser : IJsonParser
2+
{
3+
public void Parse(string input)
4+
{
5+
Console.WriteLine($"Parsing JSON: {input}");
6+
}
7+
}

AbstractFactory/ParserFactory.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class ParserFactory : IParserFactory
2+
{
3+
public IJsonParser CreateJsonParser()
4+
{
5+
return new JsonParser();
6+
}
7+
8+
public IXmlParser CreateXmlParser()
9+
{
10+
return new XmlParser();
11+
}
12+
13+
public ICsvParser CreateCsvParser()
14+
{
15+
return new CsvParser();
16+
}
17+
}

AbstractFactory/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* In this example, IParserFactory acts as the abstract factory that defines a method
2+
* for each kind of parser product (IJsonParser, IXmlParser, ICsvParser).
3+
* The ParserFactory concrete factory implements these methods, creating instances of
4+
* the concrete products (JsonParser, XmlParser, CsvParser). This pattern allows you to
5+
* introduce new parser types or parser families (factories) without changing the client
6+
* code that uses the parsers, adhering to the open/closed principle. */
7+
8+
IParserFactory parserFactory = new ParserFactory();
9+
10+
var jsonParser = parserFactory.CreateJsonParser();
11+
jsonParser.Parse("{\"name\": \"John Doe\"}");
12+
13+
var xmlParser = parserFactory.CreateXmlParser();
14+
xmlParser.Parse("<name>John Doe</name>");
15+
16+
var csvParser = parserFactory.CreateCsvParser();
17+
csvParser.Parse("name,John Doe");

AbstractFactory/XmlParser.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class XmlParser : IXmlParser
2+
{
3+
public void Parse(string input)
4+
{
5+
Console.WriteLine($"Parsing XML: {input}");
6+
}
7+
}

0 commit comments

Comments
 (0)