Considering object encapsulation, should getters return an immutable property?

前端 未结 11 537
余生分开走
余生分开走 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条回答
  •  萌比男神i
    2020-12-20 12:11

    I used to return a read-only version of the list, or at least, a copy. But each object contained in the list must be editable, unless they are immutable by design.

提交回复
热议问题