Inspect the Java classes listed below, and identify any design flaws you can see. Rewrite the classes in a way that does not change their behaviour, such that these design flaws are fixed. The process of improving the design of software without changing its behaviour is called refactoring.
In the following code it is assumed that rectangles are oriented such that the coordinate (0,0) is at the top-left of some drawing area, the x-axis extends to the right, and the y-axis extends downward. This is common in computer software, even though it is contrary to the usual mathematical setting where the y-axis extends upwards.
Note that DrawingEngine.java
is indicative of a class that could
represent the state of a drawing program. Obviously this class is incomplete:
currently it simply stores a set of rectangles. This incompleteness is not
one of the design flaws this question aims to illustrate!