Like any oops language, Solidity provides Abstract contracts. Abstracts contracts are similar to abstract classes in OOS languages such as Java and typescript.

Abstracts contracts

The abstract contract is an abstract design of a contract and the implementation contract provides the implementation of the abstract function in it.

Abstract contracts are contracts that have at least one function without implementation.

abstract Contracts are contracts that are created with abstract keywords.

Abstract functions are created with virtual keyword

Here is a syntax

pragma solidity >=0.4.0 <0.7.0;

abstract contract Animal {
    function eat() public virtual returns (bytes32);
}

Once the abstract contract is created, You need to extend it by using is keyword

Syntax

contract DerivedContract is AbstractContract

Here is an example

pragma solidity >=0.4.0 <0.7.0;

contract Lion is Animal {
    function eat() public view returns(
      string memory){
        return _strIn;
    }(bytes32){

    }
}

Notes:

  • Abstract 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