protected data in abstract class

前端 未结 8 1694
闹比i
闹比i 2021-01-01 19:01

My question involves specifically Java, abstract classes, and the use of protected data. I am being told that all the data should be private, and protected getters/setters

8条回答
  •  -上瘾入骨i
    2021-01-01 19:48

    If the field is private and access is through getters and setters, you will be able to reimplement getters and setters (for instance, dropping the field and updating/reading the value from an external source), and thus change how the "field" works without touching any child classes.

    Whether this is worth it, that's up to you.

提交回复
热议问题