This is an excellent piece of work @skplunkerin
Your final solution meets all of the assignment objectives, and you’ve documented really well how you’ve improved your initial version, and the reasons for your modifications
Even though your final version is an improvement, your initial version does still demonstrate some great knowledge of abstract contracts and function overriding. I’ll give you some additional feedback on this first version in a separate post.
Final version – a couple of additional observations
(1)
The destroy() function doesn’t need to be marked payable
. Only functions that receive ether into the contract (adding it to the contract balance) should be marked payable
. Functions that only send ether out of the contract (deducting it from the contract balance) should remain non-payable.
Marking the destroy() function as payable doesn’t prevent your code from compiling, or the function from executing, but it is bad practice and poor risk management not to restrict a function to non-payable if it doesn’t need to receive ether. This is because if someone sends ether by mistake, this amount will still be transferred to the contract. As we are programming money, we need our code to be as risk-averse as possible.
In actual fact, because the destroy() function transfers the remaining contract balance to the contract owner, if any ether was sent by mistake, it would immediately be returned together with the rest of the contract balance anyway; so in this particular case there can be no adverse effect from making the function payable. However, in other cases it could have adverse effects, and so it’s best not to get into bad habits.
(2)
In Solidity, the convention is to start the names of mappings and functions with a lower case letter — the same as with the names of variables, arrays, arguments, parameters and modifers. The names of events, structs, contracts and interfaces usually start with a capital letter. Doing the opposite will not prevent your code from compiling, but following this generally accepted convention does apply a consistency to our code, which can make it more readable.
As always, just let me know if you have any questions