Java Conventions: use getters/setters WITHIN the class?

前端 未结 12 1780
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 02:32

My professor really emphasizes protecting against privacy leaks by always using accessors and mutators to access private instance variables; however, do I have to use the ge

12条回答
  •  [愿得一人]
    2020-11-30 02:58

    You can use the accessors and mutators, but its a messy standard to follow.

    It clutters up your code and confuses anyone trying to read it thinking it might not be a part of your class.

    Basically, just access the variables directly from inside your class, and indirectly from anywhere else.

提交回复
热议问题