static void SOLIDLiskovSubstitutuion() { RectangleWithViolatingLiskovSubstitutionPrinciple rcWithViolatingLiskovSubstitutionPrinciple = new RectangleWithViolatingLiskovSubstitutionPrinciple(2, 3); Console.WriteLine($"{rcWithViolatingLiskovSubstitutionPrinciple} has area {AreaWithViolatingLiskovSubstitutionPrinciple(rcWithViolatingLiskovSubstitutionPrinciple)}"); // should be able to substitute a base type for a subtype /*Square*/ RectangleWithViolatingLiskovSubstitutionPrinciple sqWithViolatingLiskovSubstitutionPrinciple = new RectangleWithViolatingLiskovSubstitutionPrinciple(); sqWithViolatingLiskovSubstitutionPrinciple.Width = 4; Console.WriteLine($"{sqWithViolatingLiskovSubstitutionPrinciple } has area {AreaWithViolatingLiskovSubstitutionPrinciple(sqWithViolatingLiskovSubstitutionPrinciple)}"); // Without violating Liskov Substitutuion Principle Rectangle rc = new Rectangle(2, 3); Console.WriteLine($"{rc} has area {Area(rc)}"); // should be able to substitute a base type for a subtype /*Square*/ Rectangle sq = new Square(); sq.Width = 4; Console.WriteLine($"{sq} has area {Area(sq)}"); }
static public int AreaWithViolatingLiskovSubstitutionPrinciple(RectangleWithViolatingLiskovSubstitutionPrinciple r) => r.Width * r.Height;