I want to implement a contract like the
ERC20Detailed.sol
example from open Zeppelin:
My question: why setting a private variable and then, creating a getter for the same variable when the solidity compiler can automatically create the getter for a public variable ?
According to Solidity: private vs public variables it seams there is no advantage of doing that.
Am I missing something ?
Best Answer
I see good observations about style but I didn't see the safety aspect.
Setting a variable to private ensures that it can only be manipulated via functions in the contract designed for that purpose and never by a successor contract that inherited it.
That means an errant contract could not accidentally zero out, say,
owner
... a potentially disastrous accident that is preventable withprivate
.So, it's worth considering for vital state elements.
Hope it helps.
UPDATE