The purpose of inheritance is to inherit and extend.
So my question is that if child class have more method that will it break the LSP ? So in my example I have 2 classes Rectangle and Square. Square is child of Rectangle. Now both have 2 different methods HelloRectangle and HelloSquare. So will it breack LSP or not ?
public class Rectangle
{
//public int Width { get; set; }
//public int Height { get; set; }
public virtual int Width { get; set; }
public virtual int Height { get; set; }
public Rectangle()
{
}
public Rectangle(int width, int height)
{
Width = width;
Height = height;
}
public override string ToString()
{
return $"{nameof(Width)}: {Width}, {nameof(Height)}: {Height}";
}
public string HelloRectangle()
{
return "Hello Rectangle";
}
}
public class Square : Rectangle
{
public override int Width // nasty side effects
{
set { base.Width = base.Height = value; }
}
public override int Height
{
set { base.Width = base.Height = value; }
}
public string HelloSquare()
{
return "Hello Square";
}
}