Like any oops language, Solidity provides Abstract contracts. Abstracts contracts are similar to abstract classes in OOS language such as Java and typescript.
Abstracts contracts
Abstract contract is an abstract design of an contract and implementation contract provides the implementation to abstract function in it.
Abstract contracts are contract that have at least one function without implementation.
abstract Contract are contracts that created with abstract keyword.
Abstract functions are created with virtual keyword
Here is an syntax
pragma solidity >=0.4.0 <0.7.0;
abstract contract Animal {
function eat() public virtual returns (bytes32);
}
Once abstract contract is created, You need to extend by using is keyword
Syntax
contract DerivedContract is AbstractContract
Here is an exmaple
pragma solidity >=0.4.0 <0.7.0;
contract Lion is Animal {
function eat() public view returns(
string memory){
return _strIn;
}(bytes32){
}
}
Notes:
- Absttract contracts created with abstract keyword
- Functions defined in Abstract without implementation created with virtual keyword
- It is not possible with creating an instance of an Abstract contracts