Considering object encapsulation, should getters return an immutable property?

前端 未结 11 549
余生分开走
余生分开走 2020-12-20 11:38

When a getter returns a property, such as returning a List of other related objects, should that list and it\'s objects be immutable to prevent code outside of

11条回答
  •  误落风尘
    2020-12-20 12:22

    If you have control of the calling code then what matters most is that the choice you make is documented well in all the right places.

提交回复
热议问题