Тема: Оптимізувати код Java
Завдання полягає в наступному:
Shape клас забезпечує метод draw(...)...для малювання фігур. Перемістіть метод draw(...) до Rectangle класу. Будь-ласка запропонуйте інші вирішення для покращення якості коду
public class Shape {
    private String title;
    //Other fields, constructors, get, set, etc.
    public Shape(String title) {
        this.title = title;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    private void draw(Graphics graphics, Rectangle rectangle) {
        rectangle.setVisible(false);
        graphics.setColor(rectangle.getColor());
        graphics.drawLine(rectangle.getX1(),rectangle.getY1(),rectangle.getX2(),rectangle.getY2());
        //Other code
        rectangle.setVisible(true);
    }
}
public class Rectangle{
    private int x1, y1;
    private int x2, y2;
    private Color color;
    private boolean visible;
    //Othre fields, constructors, get, set, etc
    public Rectangle(String title, int x1, int y1, int x2, int y2, Color color, boolean visible) {
        super(title);
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
        this.color = color;
        this.visible = visible;
    }
    public int getX1() {
        return x1;
    }
    public int getY1() {
        return y1;
    }
    public int getX2() {
        return x2;
    }
    public int getY2() {
        return y2;
    }
    public Color getColor() {
        return color;
    }
    public boolean getVisible() {
        return visible;
    }
    public void setVisible(boolean visible) {
        this.visible = visible;
    }
}На мою думку якщо я перенесу метод draw () до Rectangle класу, то можна буде з цього методу забрати параметр "Rectangle rectangle" і використовувати методи не так "rectangle.setVisible (false)" а так "setVisible (false)"
Що ще тут ще можна поліпшити?

