The way different programming languages implement the mapping of runtime polymorphic values to code both at the source level and in the language implementation is a defining characteristic. There are two opposite approaches that languages facilitate to varying degrees:
- Interfaces / Traits / Abstract Classes / Inheritance / Method Overriding (from here on, just "Interfaces")
- Sum Types / Algebraic Data Types / Tagged Unions / Pattern Matching (from here on, just "Sum Types")
You have two types: A
, containing a string, and B
, containing an int, and two operations: x
and y
.