There are two ways to implement behavior subtyping: nominal subtyping and structural subtyping:
- With nominal subtyping, you must explicitly define the relationship between a type and its supertype. Julia uses nominal subtyping, where types are explicitly annotated in function arguments. That is why a type hierarchy needs to be built to express type relationships.
- With structural subtyping, the relationship is implicitly derived as long as the subtype implements the required functions from the supertype. Julia supports structural subtyping when functions are defined with arguments and not annotated with any type.
Julia supports structural subtyping via duck typing. We first mentioned duck typing in Chapter 3, Designing ...