Class Features Provided by Solidity
This article discusses Class Features provided by Solidity, the defacto smart contract language for the Ethereum blockchain.
Background
During the development and testing of Datona Labs’ Solidity Smart-Data-Access-Contract (S-DAC) templates, we explored techniques for using classes, just like in traditional object-orientated programming (OOP) languages. For example, we desire to write something close to this:
import "ContractOwner.sol";
import "Partners.sol";contract EasyShare ... { ContractOwner contractOwner; Partners partners;
... function addPartner(...) public onlyContractOwner {
partners.add(...);
} ...
}
In this example, ContractOwner and Partners are the classes we want to use.
A class encapsulates associated code and data in a single entity.
The realisation of this is explored further in the example expanded below.
Why use classes in Solidity?
Because we are familar with developing OOP solutions using classes and would like to continue to develop…