This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WhoisLookup | |
{ | |
private readonly string webApiBaseAddress = "http://api.hackertarget.com/whois/?q="; | |
public string HostToLookup { get; private set; } | |
public WhoisLookup(string hostToLookup) | |
{ | |
HostToLookup = hostToLookup; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Money | |
{ | |
public decimal Amount { get; private set; } = 20m; | |
public void doStuff() | |
{ | |
Amount *= 2; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person | |
{ | |
// Example 1: manually implemented property | |
private string _name; | |
public string Name | |
{ | |
get | |
{ | |
return _name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApplication | |
{ | |
public class Program | |
{ | |
static void Main() | |
{ | |
Console.WriteLine(getWithTernaryOperator()); | |
Console.WriteLine(getWithNullCoalescingOperator()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Engine | |
{ | |
public bool IsRunning { get; private set; } | |
public void Start() { } | |
public void Stop() { } | |
} | |
class Machine | |
{ | |
public Engine Engine { get; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
PowerOf2Example(); | |
} | |
private static void PowerOf2Example() | |
{ | |
var numbers = new List<int>() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
{ | |
public int Age { get; } | |
public string Name { get; } | |
public Person(int age, string name) | |
{ | |
this.Age = age; | |
this.Name = name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace LiskovSubstitutionPrinciple.Violation | |
{ | |
public class Rectangle | |
{ | |
protected int _width; | |
protected int _height; | |
public virtual int Height | |
{ | |
get { return _height; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace LiskovSubstitutionPrinciple.Tests | |
{ | |
[TestFixture] | |
public class Violation | |
{ | |
[Test] | |
public void RectangleIsOkay() | |
{ | |
Rectangle rect = new Rectangle | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Open_Closed_Principle.Violation | |
{ | |
public class AvgTemperatureReader | |
{ | |
public double GetAverageTemperature(List<object> temperatureSensors) | |
{ | |
double total = 0; | |
int count = 0; | |
foreach (var temperatureSensor in temperatureSensors.OfType<IndoorTemperatureSensor>()) |