Solidity – How to Call Private/Internal Function from External Function in Solidity

accessdesign-patternssolidityvisibility

what the purpose of that way to restrict access to function call?

    function updateQuorumNumerator(uint256 newQuorumNumerator) external virtual onlyGovernance {
        _updateQuorumNumerator(newQuorumNumerator);
    }

    function _updateQuorumNumerator(uint256 newQuorumNumerator) internal virtual {
        require(
            newQuorumNumerator <= quorumDenominator(),
            "GovernorVotesQuorumFraction: quorumNumerator over quorumDenominator"
        );

        uint256 oldQuorumNumerator = _quorumNumerator;
        _quorumNumerator = newQuorumNumerator;

        emit QuorumNumeratorUpdated(oldQuorumNumerator, newQuorumNumerator);
    }

Why can't we just make _updateQuorumNumerator external and add modifier onlyGovernance to it?

Best Answer

One possible reason is for the sake of inheritance. If you wanted to use the logic within _updateQuorumNumerator without the onlyGovernance modifier in a child smart contract, you would want the external and internal logic to be separated.
It can simply be better to separate the two if you're going to allow the contract to be inherited from. By separating the two functionalities (external access and internal logic), you are maximizing code reusability.

Related Topic