Animal polymorphism class diagram
Dog and cat inherit from animal and implement speak differently: the standard picture for polymorphism.
The diagram
Reading it step by step
- 'Animal' (abstract class): 1 attributes, 1 methods.
- 'Dog' (class): 0 attributes, 2 methods.
- 'Cat' (class): 0 attributes, 1 methods.
- 'Dog' inherits from 'Animal'.
- 'Cat' inherits from 'Animal'.
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Animal | abstract | holds #name String, +speak() String · ← Dog, Cat |
| Dog | Class | holds +speak() String, +walk() void · → Animal |
| Cat | Class | holds +speak() String · → Animal |
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.
# Animal polymorphism class diagram
classDiagram
class Animal {
<<abstract>>
#name String
+speak() String
}
class Dog {
+speak() String
+walk() void
}
class Cat {
+speak() String
}
Animal <|-- Dog
Animal <|-- Cat