Contract polymorphism

Contract polymorphism refers to using multiple contract instances interchangeably when the contracts are related to each other by way of inheritance. Contract polymorphism helps in invoking derived contract functions using a base contract instance.

Let's understand this concept with the help of code listing shown next.

A parent contract contains two functions, SetInteger and GetInteger. A child contract inherits from a parent contract and provides its own implementation of GetInteger. The child contract can be created using the ChildContract variable data type and it can also be created using the parent contract data type. Polymorphism allows the use of any contract in a parent-child relationship with the base type contract ...

Get Solidity Programming Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.