Shape inheritance class diagram
Circle and rectangle inherit from an abstract shape, the first inheritance example most classes use. Each child redefines the area method.
The diagram
Reading it step by step
- 'Shape' (abstract class): 1 attributes, 1 methods.
- 'Circle' (class): 1 attributes, 1 methods.
- 'Rectangle' (class): 2 attributes, 1 methods.
- 'Circle' inherits from 'Shape'.
- 'Rectangle' inherits from 'Shape'.
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Shape | abstract | holds +color String, +area() double · ← Circle, Rectangle |
| Circle | Class | holds +radius double, +area() double · → Shape |
| Rectangle | Class | holds +width double, +height double, +area() double · → Shape |
Symbols used here
| Symbol | Meaning |
|---|---|
| Class | A box with name, attributes and methods. |
| Inheritance | Solid line from child to parent, hollow triangle at the parent. |
Diagram text
Paste this text into the editor to get the same picture, then change the names to fit your own work.
# Shape inheritance class diagram
classDiagram
class Shape {
<<abstract>>
+color String
+area() double
}
class Circle {
+radius double
+area() double
}
class Rectangle {
+width double
+height double
+area() double
}
Shape <|-- Circle
Shape <|-- Rectangle