diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07c74bf --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +/SRP/.vs +/SRP/SRP/bin +/SRP/SRP/obj +/OCP_First_Example/.vs +/OCP_First_Example/OCP_First_Example/bin +/OCP_First_Example/OCP_First_Example/obj +/OCP_Second_Example/.vs +/OCP_Second_Example/OCP_Second_Example/bin +/OCP_Second_Example/OCP_Second_Example/obj +/DIP/.vs +/DIP/DIP/bin +/DIP/DIP/obj diff --git a/DIP/DIP.sln b/DIP/DIP.sln new file mode 100644 index 0000000..a651a36 --- /dev/null +++ b/DIP/DIP.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.168 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DIP", "DIP\DIP.csproj", "{6CC8448A-93CD-42DF-AF04-72C08A87B686}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6CC8448A-93CD-42DF-AF04-72C08A87B686}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CC8448A-93CD-42DF-AF04-72C08A87B686}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CC8448A-93CD-42DF-AF04-72C08A87B686}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CC8448A-93CD-42DF-AF04-72C08A87B686}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {210AF8BA-7357-4817-A716-A29CBA522746} + EndGlobalSection +EndGlobal diff --git a/DIP/DIP/DIP.csproj b/DIP/DIP/DIP.csproj new file mode 100644 index 0000000..51be1a2 --- /dev/null +++ b/DIP/DIP/DIP.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + + \ No newline at end of file diff --git a/DIP/DIP/Employee.cs b/DIP/DIP/Employee.cs new file mode 100644 index 0000000..c058902 --- /dev/null +++ b/DIP/DIP/Employee.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DIP +{ + public class Employee + { + public string Name { get; set; } + public Gender Gender { get; set; } + public Position Position { get; set; } + } +} diff --git a/DIP/DIP/EmployeeManager.cs b/DIP/DIP/EmployeeManager.cs new file mode 100644 index 0000000..5f2ceee --- /dev/null +++ b/DIP/DIP/EmployeeManager.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DIP +{ + public class EmployeeManager: IEmployeeSerchable + { + private readonly List _employees; + + public EmployeeManager() + { + _employees = new List(); + } + + public void AddEmployee(Employee employee) + { + _employees.Add(employee); + } + + public IEnumerable GetEmployeesByGenderAndPosition(Gender gender, Position position) + => _employees.Where(emp => emp.Gender == gender && emp.Position == position); + } +} diff --git a/DIP/DIP/EmployeeStatistics.cs b/DIP/DIP/EmployeeStatistics.cs new file mode 100644 index 0000000..590c3f2 --- /dev/null +++ b/DIP/DIP/EmployeeStatistics.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DIP +{ + public class EmployeeStatistics + { + private readonly IEmployeeSerchable _emp; + + public EmployeeStatistics(IEmployeeSerchable emp) + { + _emp = emp; + } + + public int CountFemaleManagers() => + _emp.GetEmployeesByGenderAndPosition(Gender.Female, Position.Manager).Count(); + } +} diff --git a/DIP/DIP/Gender.cs b/DIP/DIP/Gender.cs new file mode 100644 index 0000000..414904d --- /dev/null +++ b/DIP/DIP/Gender.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DIP +{ + public enum Gender + { + Male, + Female + } +} diff --git a/DIP/DIP/IEmployeeSerchable.cs b/DIP/DIP/IEmployeeSerchable.cs new file mode 100644 index 0000000..79d0d34 --- /dev/null +++ b/DIP/DIP/IEmployeeSerchable.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DIP +{ + public interface IEmployeeSerchable + { + IEnumerable GetEmployeesByGenderAndPosition(Gender gender, Position position); + } +} diff --git a/DIP/DIP/Position.cs b/DIP/DIP/Position.cs new file mode 100644 index 0000000..d27a21a --- /dev/null +++ b/DIP/DIP/Position.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DIP +{ + public enum Position + { + Administrator, + Manager, + Executive + } +} diff --git a/DIP/DIP/Program.cs b/DIP/DIP/Program.cs new file mode 100644 index 0000000..449ef5f --- /dev/null +++ b/DIP/DIP/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DIP +{ + class Program + { + static void Main(string[] args) + { + var empManager = new EmployeeManager(); + empManager.AddEmployee(new Employee { Name = "Leen", Gender = Gender.Female, Position = Position.Manager }); + empManager.AddEmployee(new Employee { Name = "Mike", Gender = Gender.Male, Position = Position.Administrator }); + + var stats = new EmployeeStatistics(empManager); + Console.WriteLine($"Number of female managers in our company is: {stats.CountFemaleManagers()}"); + } + } +} diff --git a/README.md b/README.md index c1b61e8..123009f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# solid-principles-csharp -This repository contains source code for the SOLID principles in C# on Code Maze blog +# Liskov Substitution Principle +## https://code-maze.com/dependency-inversion-principle/ +