Suppose I have these classes :
class Square1 //////////
{
private int side = 0; //private field
public Square1(int side) //constructor
{
this.side = side;
}
public int GetArea() //public method
{
return side * side;
}
}
class Square2 //////////
{
private int side = 0; //private field
public Square2(int side) //constructor
{
this.side = side;
}
public int Area //public property
{
get { return side * side; }
}
}
I had other methods or properties here to set the value of side, but left them out to keep it simple.
The only thing I want to expose is a calculated value of area.
What is the best option here? I think data encapsulation is taking care of in both cases, or am I wrong?
Suppose I want to derive from a Square class, call it a SuperSquare class, what is the best option? (A square drawn on a flat wall has another area then a square with the same sides drawn on a football. So I should override the area calculation in some way.)