Skip to content

Instantly share code, notes, and snippets.

@kolosovpetro
Created April 9, 2021 21:17
Show Gist options
  • Select an option

  • Save kolosovpetro/9617663f25030bf700547182c291e17e to your computer and use it in GitHub Desktop.

Select an option

Save kolosovpetro/9617663f25030bf700547182c291e17e to your computer and use it in GitHub Desktop.
namespace SolidRules.LSP
{
public class Rectangle
{
protected double Width { get; }
private double Height { get; }
public Rectangle(double width, double height)
{
Width = width;
Height = height;
}
public virtual double GetSquare() => Width * Height;
}
// violates LSP
public class Square : Rectangle
{
public override double GetSquare() => Width * Width;
public Square(double width, double height) : base(width, height) { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment