Why are protected variables not allowed by default in Checkstyle?

前端 未结 3 1296
旧时难觅i
旧时难觅i 2021-01-03 18:07

I get a lot of warnings in eclipse like these:

Variable \'myVariable\' must be private and have accessor methods.

I think I get

3条回答
  •  时光说笑
    2021-01-03 18:42

    I guess, making everything private is an anti-pattern. Often classes are used in a bunch and as a whole represent encapsulated entity placed in separate package. They do not need to hide something from each other, but this rule enforces hiding for no good reason, increasing clutter and effectively making style (as I understand it) worse. Meanwhile, we often see that every class in package is public. I guess this is much worse, but checkstyle doesn't check that.

    Encapsulation exists not only on class level, put also on package, system and so on. And I think that these levels are even more important.

提交回复
热议问题