On 13 May 2014, at 3:47 PM, David Astels <dast...@icloud.com> wrote:
> Well, an issue of good OO design or not.  Returning a mutable collection 
> breaks encapsulation. My initial question is whether the collection is simply 
> a detail of the implementation or part of the external interface you want to 
> expose. If the former, hide the collection and expose operations that provide 
> what’s truly needed. If the latter, then you might need immutable 
> collections. 

Agree 100% with David’s comment, it’s an issue of good OO design and there are 
valid cases to return immutable collections.
I think most developers return internal collections, breaking encapsulation, 
but get away with it 99% of the time and only occasionally get burnt with a 
nasty bug or a deep mess.

Cheers
Carlo

Reply via email to