Should I actually use getters and setters for all public variables in classes? [duplicate]

1

So this subject seems very controversial but at the same time I do not see a compromise between the developers.

  • Some say that getters and setters are 100% rule to access any variable within a class. That is, if I have 10 variables, I will have 10 getters and 10 setters;
  • It should be said that getters and setters should be used only for specific situations;
  • Finally there are those who argue that you should not use absolute getters and setters for public variables, since they are public and easily accessible.
  • So, in a simple structure like this:

    class exemplo
    {
    public:
        int a, b, c, d, e, f;
        string g, h, i, j;
        double k, l, m, n, o, p, q, r, s, t;
    };
    

    ... where there are 20 public variables, do I really have 20 getters and 20 setters?

        
    asked by anonymous 23.05.2018 / 16:55

    0 answers