Implementing simple solutions with inheritance
We will continue to use the previous Bank
and BankClient
smart contracts and keep improving them to incorporate upgradability therein.
This solution abstracts the storage or state variables from the smart contract and places them in a different smart contract. Having state and functionality in two separate smart contracts assists in reusing existing smart contracts using the dependency injection pattern that we learned about in the Understanding dependency injection section.
In the next example, a new smart contract named BankStorage
is listed. This contract just has a declaration for the storage variables. They can additionally have functions whose purpose is to provide read-write functionality for the storage variables. The previous Bank
contract has been refactored by removing the state variable to the BankStorage
contract.
Next, we create the Bank
contract; however, this time we inherit from the BankStorage
contract. Inheriting...