Initialize a collection within an object?

后端 未结 10 1247
长发绾君心
长发绾君心 2021-02-04 15:03

If an object has a property that is a collection, should the object create the collection object or make a consumer check for null? I know the consumer should not assume, just

10条回答
  •  太阳男子
    2021-02-04 15:17

    I've tried both ways and I am usually happy when I find I have already instanciated it. Alternatively you could hide the the implementation from the consumer behind a set of methods that can handle the check for you.

提交回复
热议问题