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
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions DIP/DIP.sln
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions DIP/DIP/DIP.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

</Project>
15 changes: 15 additions & 0 deletions DIP/DIP/Employee.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
26 changes: 26 additions & 0 deletions DIP/DIP/EmployeeManager.cs
Original file line number Diff line number Diff line change
@@ -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<Employee> _employees;

public EmployeeManager()
{
_employees = new List<Employee>();
}

public void AddEmployee(Employee employee)
{
_employees.Add(employee);
}

public IEnumerable<Employee> GetEmployeesByGenderAndPosition(Gender gender, Position position)
=> _employees.Where(emp => emp.Gender == gender && emp.Position == position);
}
}
21 changes: 21 additions & 0 deletions DIP/DIP/EmployeeStatistics.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
14 changes: 14 additions & 0 deletions DIP/DIP/Gender.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
13 changes: 13 additions & 0 deletions DIP/DIP/IEmployeeSerchable.cs
Original file line number Diff line number Diff line change
@@ -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<Employee> GetEmployeesByGenderAndPosition(Gender gender, Position position);
}
}
15 changes: 15 additions & 0 deletions DIP/DIP/Position.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
21 changes: 21 additions & 0 deletions DIP/DIP/Program.cs
Original file line number Diff line number Diff line change
@@ -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()}");
}
}
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/