Solidity – Abstract Contract
Abstract contracts are contracts that have at least one function without its implementation or in the case when you don’t provide arguments for all of the base contract constructors. Also in the case when we don’t intend to create a contract directly we can consider the contract to be abstract. An instance of an abstract cannot be created. Abstract contracts are used as base contracts so that the child contract can inherit and utilize its functions. The abstract contract defines the structure of the contract and any derived contract inherited from it should provide an implementation for the incomplete functions, and if the derived contract is also not implementing the incomplete functions then that derived contract will also be marked as abstract. An abstract contract is declared using the abstract keyword.
Example: In the below example, an abstract contract is created which is inherited by another contract that has implemented all the functions of the abstract contract. Abstract contract instance is created in the calling contract and an object of the child contract is created. Using the object of the child contract all the abstract functions that are implemented in the child contract are invoked.
Here, abstractContract contract is an abstract contract that has some functions without their implementation, and derivedContract is its child contract. The getStr() and setValues() functions takes string and values, while the add() function adds the values of setValues() function. abs is an object of abstractContract which creates an instance of derivedContract in call contract that uses the variables of the contract and calls the functions.