In the first section, we implemented 5 classes. In this section, we then show you how to use UML class diagrams to design the remaining classes. To reduce space, this section focuses on UML class diagrams and applications, the Java implementation code is no longer described in detail.
Six, Cgpoint class
The Cgpoint class illustrates how to extend an abstract class with a Non-abstract class. The Cgpoint class is a subclass of Cgobject, the Cgpoint class extends the Cgobject class, and the Cgpoint class does not add a variable to the variable it inherits, the method it declares is only a constructor and an abstract method that requires it to implement. Its class diagram is as follows:
The Java implementation code is:
Seven, Cgbox class
The Cgbox class also extends the Cgobject class. The Cgbox class provides additional variables for displaying rectangles on a grid. The class diagram of the Cgbox class is as follows:
The corresponding code is: