Представим пример системы автоматизированного проектирования, которая рисует на экране изображения:
//: reusing/CADSystem.java // Обеспечение необходимого завершения package reusing:
import static net.mindview util.Print.*;
class Shape {
Shape(int i) { print("Конструктор Shape"); } void disposed { print("Завершение Shape"); }
'}
class Circle extends Shape { Circle(int i) {
super(i),
print("Рисуем окружность Circle");
}
void disposeO {
print("Стираем окружность Circle"); super. disposeO;
}
}
class Triangle extends Shape { Triangle(int i) { super(i);
print("Рисуем треугольник Triangle");
}
void disposeO {
print("Стираем треугольник Triangle"); super.disposeO;
}
}
class Line extends Shape { private int start, end; Line(int start, int end) { super(start); this.start = start; this.end = end;
print("Рисуем линию Line: " + start + ", " + end);
}
void disposeO {
print("Стираем линию Line: " + start + ", " + end). super.disposeO;
}
public class CADSystem extends Shape { private Circle c; private Triangle t; private Line[] lines = new Line[3], public CADSystem(int i) { super(i + 1).
for(int j = 0, j < lines length; j++) lines[j] = new Line(j. j*j), с = new Circled), t = new Triangle(l), print("Комбинированный конструктор").
}