In fact, there are only two kinds of geometric shapes: an elliptical shape (circular shape) and a Polygon Shape (having a certain number of edges ). A circle is an elliptical type with only one focal point. Triangles, rectangles, and Pentagons are polygon with different numbers of edges. A square is a type of rectangle with equal lengths of all edges. This constitutes a perfect inheritance relationship.
In this example, Shape is the base class of Ellipse and Polygon (inherited from all classes ). An ellipse has an attribute.Foci, Indicating the number of focal points that an elliptic has. The Circle inherits the elliptical shape, so the circular shape is a subclass of the elliptical shape (subclass) and the elliptical shape is a superclass of the circular shape (superclass ). Likewise, triangles, rectangles, and Pentagons are subclasses of polygon, and polygon are their superclasses. Finally, Square inherits the rectangle.
It is best to use diagrams to explain this inheritance relationship, which is the application of UML (Unified Modeling Language. One of the main purposes of UML is to visually represent complex object relationships such as inheritance. Figure 4-1 is a UML diagram that explains the relationship between a Shape and its subclass.
In UML, each box represents a class, which is described by the class name. The line segments at the top of the Triangle, Rectangle, and Pentagon are combined to point to the Shape, indicating that these classes are inherited by the Shape. Similarly, the arrow pointing from Square to Rectangle illustrates the inheritance relationship between them.
If you are interested in learning UML, you can refer to the "UML User Guide (second edition)" by the three UML founders.