56 lines
2.1 KiB
Java
56 lines
2.1 KiB
Java
/**
|
|
* Answers the question.
|
|
*
|
|
* Question3:
|
|
*
|
|
* - Q: What is the problem with the resize method of the Shape calss? How do
|
|
* you solve this problem?
|
|
*
|
|
* - A: The resize method of the Dot class is inherited from the Shape class.
|
|
* which does not have a throw Exception declared. We can solve this problem by
|
|
* declaring the resize method in the Shape class as a throw Exception.
|
|
*
|
|
* - Q: Do you need to change the resize method of the Circle class then?
|
|
*
|
|
* - A: No, we do not need to change the resize method of the Circle class.
|
|
*
|
|
* - Q: Does the Square class need its own area and resize method or not?
|
|
*
|
|
* - A: No, but it depends. Currently the Square.area and Square.resize methods
|
|
* return the correct values. But in the future, if we want to change the
|
|
* Rectangle.area and Rectangle.resize methods, the Square class may give the
|
|
* wrong values. So it is better to have its own area and resize methods.
|
|
*
|
|
* - Q: What is then the problem for the Square class?
|
|
*
|
|
* - A: No problem. The area method is overloaded. But the resize method in
|
|
* Square can set different values for the width and height. So it is better to
|
|
* have its own resize methods.
|
|
*
|
|
* - Q: What happends with the resize method of the Rectangle class?
|
|
*
|
|
* - A: The resize method of the Square class is inherited from the Rectangle
|
|
* class. So we need to add the throws Exception to the resize method of the
|
|
* Square class.
|
|
*
|
|
* - Q: What is then the problem for the Shape class?
|
|
*
|
|
* - A: The resize method of the Circle class is inherited from the Shape class.
|
|
* Circle.resize() method does throw a BadRadiusException, but its parent class
|
|
* Shape.resize() method does not throw a BadRadiusException, instead it throws
|
|
* a CannotResizeException. So we can solve this problem by declaring the parent
|
|
* class of BadRadiusException and CannotResizeException as a throw Exception.
|
|
* Or we can solve this problem by declaring both BadRadiusException and
|
|
* CannotResizeException in the Shape class.
|
|
*/
|
|
|
|
public class Start {
|
|
public static void main(String[] args) {
|
|
Shape.testShape();
|
|
Circle.testCircle();
|
|
Dot.testDot();
|
|
Rectangle.testRectangle();
|
|
Square.testSquare();
|
|
}
|
|
}
|