Im was reading an example of simple inheritence and came across the basic idea that a square is a base type and a rectangle is derived from a square.
The example for setting the square dimensions used a property called Size.
The example for the rectangle then went on to use Width and Height.
This didnt make sense in my head, so I coded it.
The problem seems to be that when accessing rectangle, there will always be a confusing property called 'Size' present.
Have I got this right? Or is there a way to hide other classes from seeing Size when looking at rectangle?
public class square
{
public int Size { get; set; }
public square(int size)
{
this.Size = size;
}
}
public class rectangle : square
{
public int Width { get { return base.Size; } set { base.Size = value; } }
public int Height { get; set; }
public rectangle(int width, int height)
: base(width)
{
Height = height;
}
}
SquareorRectangleyou can't mutate an object of either type), so care to comment on how that makes my answer "dead wrong?"