Why are state variables private rather than public in OpenZeppelin Contracts?

Hi @franco_villa_santana,

(Thanks @Skyge as always for being awesome :pray:)

State variables being private is part of the OpenZeppelin Contracts style guidelines:
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/GUIDELINES.md#solidity-code

The explanation for this can be found in the Release notes:

_From: https://github.com/OpenZeppelin/openzeppelin-contracts/releases/tag/v2.0.0_

All state variables are now private , which means that derived contracts cannot access them directly, but have to use getters. This is to increase encapsulation, to be able to reason better about the code.

1 Like