Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions HomeWork5-Solid/.idea/.idea.HomeWork5-Solid/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions HomeWork5-Solid/.idea/.idea.HomeWork5-Solid/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions HomeWork5-Solid/HomeWork5-Solid.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Question1", "Question1\Question1.csproj", "{6D6AFD49-DEE5-4ED9-B6A7-934D7F3259E6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Question2", "Question2\Question2.csproj", "{05647A34-C5CA-4C64-A73C-A74A55B06BA5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Question3", "Question3\Question3.csproj", "{CA6358D6-57D4-4B19-A3C1-4987DEEF156C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Question4", "Question4\Question4.csproj", "{E6524682-AE0F-449E-8531-A11D92955845}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6D6AFD49-DEE5-4ED9-B6A7-934D7F3259E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D6AFD49-DEE5-4ED9-B6A7-934D7F3259E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D6AFD49-DEE5-4ED9-B6A7-934D7F3259E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D6AFD49-DEE5-4ED9-B6A7-934D7F3259E6}.Release|Any CPU.Build.0 = Release|Any CPU
{05647A34-C5CA-4C64-A73C-A74A55B06BA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05647A34-C5CA-4C64-A73C-A74A55B06BA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05647A34-C5CA-4C64-A73C-A74A55B06BA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05647A34-C5CA-4C64-A73C-A74A55B06BA5}.Release|Any CPU.Build.0 = Release|Any CPU
{CA6358D6-57D4-4B19-A3C1-4987DEEF156C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA6358D6-57D4-4B19-A3C1-4987DEEF156C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA6358D6-57D4-4B19-A3C1-4987DEEF156C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA6358D6-57D4-4B19-A3C1-4987DEEF156C}.Release|Any CPU.Build.0 = Release|Any CPU
{E6524682-AE0F-449E-8531-A11D92955845}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6524682-AE0F-449E-8531-A11D92955845}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6524682-AE0F-449E-8531-A11D92955845}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6524682-AE0F-449E-8531-A11D92955845}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
3 changes: 3 additions & 0 deletions HomeWork5-Solid/Question1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// See https://aka.ms/new-console-template for more information

Console.WriteLine("Hello, World!");
10 changes: 10 additions & 0 deletions HomeWork5-Solid/Question1/Question1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Binary file added HomeWork5-Solid/Question1/answer.pdf
Binary file not shown.
68 changes: 68 additions & 0 deletions HomeWork5-Solid/Question2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;

public interface IProductRepository
{
List<string> GetProducts();
}

public class DatabaseProductRepository : IProductRepository
{
public List<string> GetProducts()
{
return new List<string> { "Database Product 1", "Database Product 2" };
}
}

public class ApiProductRepository : IProductRepository
{
public List<string> GetProducts()
{
return new List<string> { "API Product 1", "API Product 2" };
}
}

public class FileProductRepository : IProductRepository
{
public List<string> GetProducts()
{
return new List<string> { "File Product 1", "File Product 2" };
}
}

public class ProductDisplay
{
private readonly IProductRepository _repository;

public ProductDisplay(IProductRepository repository)
{
_repository = repository;
}

public void Display()
{
List<string> products = _repository.GetProducts();
foreach (var product in products)
{
Console.WriteLine(product);
}
}
}

class Program
{
static void Main()
{
IProductRepository dbRepo = new DatabaseProductRepository();
ProductDisplay display1 = new ProductDisplay(dbRepo);
display1.Display();

IProductRepository apiRepo = new ApiProductRepository();
ProductDisplay display2 = new ProductDisplay(apiRepo);
display2.Display();

IProductRepository fileRepo = new FileProductRepository();
ProductDisplay display3 = new ProductDisplay(fileRepo);
display3.Display();
}
}
10 changes: 10 additions & 0 deletions HomeWork5-Solid/Question2/Question2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
81 changes: 81 additions & 0 deletions HomeWork5-Solid/Question3/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;

public interface IProductRepository
{
List<string> GetProducts();
}

public class DatabaseProductRepository : IProductRepository
{
public List<string> GetProducts()
{
return new List<string> { "Database Product 1", "Database Product 2" };
}
}

public class ApiProductRepository : IProductRepository
{
public List<string> GetProducts()
{
return new List<string> { "API Product 1", "API Product 2" };
}
}

public class FileProductRepository : IProductRepository
{
public List<string> GetProducts()
{
return new List<string> { "File Product 1", "File Product 2" };
}
}

public static class ProductRepositoryFactory
{
public static IProductRepository CreateRepository(string sourceType)
{
switch (sourceType.ToLower())
{
case "database":
return new DatabaseProductRepository();
case "api":
return new ApiProductRepository();
case "file":
return new FileProductRepository();
default:
throw new ArgumentException("Invalid source type specified.");
}
}
}

public class ProductDisplay
{
private readonly IProductRepository _repository;

public ProductDisplay(IProductRepository repository)
{
_repository = repository;
}

public void Display()
{
List<string> products = _repository.GetProducts();
foreach (var product in products)
{
Console.WriteLine(product);
}
}
}

class Program
{
static void Main()
{
string configSource = "api";

IProductRepository repository = ProductRepositoryFactory.CreateRepository(configSource);

ProductDisplay display = new ProductDisplay(repository);
display.Display();
}
}
10 changes: 10 additions & 0 deletions HomeWork5-Solid/Question3/Question3.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
67 changes: 67 additions & 0 deletions HomeWork5-Solid/Question4/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;

public interface IProductRepository
{
List<string> GetProducts();
}

public class DatabaseProductRepository : IProductRepository
{
public List<string> GetProducts()
{
return new List<string> { "Database Product 1", "Database Product 2" };
}
}

public class ApiProductRepository : IProductRepository
{
public List<string> GetProducts()
{
return new List<string> { "API Product 1", "API Product 2" };
}
}

public class FileProductRepository : IProductRepository
{
public List<string> GetProducts()
{
return new List<string> { "File Product 1", "File Product 2" };
}
}

public class ProductDisplay
{
private readonly IProductRepository _repository;

public ProductDisplay(IProductRepository repository)
{
_repository = repository;
}

public void Display()
{
List<string> products = _repository.GetProducts();
foreach (var product in products)
{
Console.WriteLine(product);
}
}
}

class Program
{
static void Main()
{
var serviceCollection = new ServiceCollection();

serviceCollection.AddTransient<IProductRepository, ApiProductRepository>();
serviceCollection.AddTransient<ProductDisplay>();

var serviceProvider = serviceCollection.BuildServiceProvider();

var display = serviceProvider.GetRequiredService<ProductDisplay>();
display.Display();
}
}
10 changes: 10 additions & 0 deletions HomeWork5-Solid/Question4/Question4.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>