Beispiel #1
0
        private static void LiskovSubstitution()
        {
            var rectangle = new Rectangle(2, 4);

            Console.WriteLine($"{rectangle} has area {rectangle.Area}");

            // Will not set width properly, as it is using the Rectangle Width setter
            Rectangle badSquare = new BadSquare();

            badSquare.Height = 4;
            Console.WriteLine($"{badSquare} has area {badSquare.Area}");

            // Functionality of Square should be preserved even if it is instantiated as a rectangle
            Rectangle goodSquare = new Square();

            goodSquare.Height = 4;
            Console.WriteLine($"{goodSquare} has area {goodSquare.Area}");
        }
Beispiel #2
0
 public static double CalculateArea(BadSquare square)
 {
     return(square.Width * square.Height);
 }