Implementing simple solutions with composition
The previous section showed how to create a simple upgradable solution using inheritance. The same can be achieved using composition as well. Composition is a well-stable object-orientation concept in which objects are created by composing other objects. The other objects can live independently or can be completely dependent on the parent object.
The same example from the previous section has been used here, but refactored to use composition instead of inheritance. In this example, the BankStorage
contract has the storage variable for storing global data along with a couple of getter and setter functions for reading and writing the state variables, as shown here:
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0 contract BankStorage { mapping (address => uint256) public balances ; function SetBalance(address addr, uint256 amount) public...