

Stop Exposing Collections Already - pavel
http://davybrion.com/blog/2009/10/stop-exposing-collections-already/

======
makecheck
For what it's worth, I disagree with this idea, or any idea that basically
requires a lot of glue code without adding any real value.

This requires BOTH the API maintainer AND the caller to add code, all in the
name of avoiding some theoretical violation of encapsulation. The extra code
risks bugs, is harder to maintain, harder to read, harder to understand, and
may accidentally limit the usefulness of the return value in some critical way
(which would make the API temporarily unusable while some bug is opened to
have the API expanded).

There's a lot of things they could try first, including simply adding
documentation to tell the caller what must not happen to the collection that
is returned.

~~~
shantanu_k06
I second that. If you are using Java, simply return
Collections.unmodifiableList(listObject);

~~~
kentosi
Thanks for that. I was going to comment that the article carries a very
complaining tone without giving any real solutions.

