Polymorphism
Poly means many and morph means forms. Together, the word polymorphism means multiple forms. It means that contracts in inheritance can be accessed using a common interface. It also means that multiple functions with the same name can be defined and invoked using different objects. There are the following two types of polymorphism:
- Function polymorphism
- Contract polymorphism
Function polymorphism
Function polymorphism refers to declaring multiple functions within the same contract or inheriting contracts with the same name. The functions differ in the parameter data types or the number of parameters. Return types are not taken into consideration for determining valid function signatures for polymorphism. This is also known as method overloading.
The following code segment illustrates a contract that contains two functions that have the same name but different data types for incoming parameters. The first function, getVariableData
, accepts int8
...