Posts

Showing posts from August, 2021

SOLID Principles cheat sheet in C#

Image
A summary of SOLID Principles as implemented in the C# language. Useful link: https://code-maze.com/solid-principles/ 1. Single Responsibility Principle Every class should have only one responsibility. Consider the class PersonalDetails whose responsibility is to hold details about a person: [code language="java"] public class PersonDetails { public string Name { get; set; } public int Age { get; set; } public string Identifier { get; set; } public void PrintReport() { Console.WriteLine("Name: " + Name); Console.WriteLine("Age: " + Age.ToString()); Console.WriteLine("Identifier: " + Identifier); } } [/code] After instantiating, we then use a public method to print out the details of that person: [code language="java"] PersonDetails person1 = new PersonDetails { Name = "Andrew", Age = 36, Identifier = "MDJW0031" }; person1.PrintReport(); [...