protected data in abstract class

前端 未结 8 1738
闹比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:32

    Information hiding is valuable, even among classes related by inheritance.

    In addition to allowing re-implementation, as noted by alex above:

    • You can set breakpoints in methods.
    • You can add constraints in one place.

提交回复
热议问题