Created
April 9, 2021 21:17
-
-
Save kolosovpetro/9617663f25030bf700547182c291e17e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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