Reputation: 23615
i use a readonly collection to prevent users from altering my cached data, but the items themselves are ofcourse muatble. Is there a way to prevent that behaviour?
Michel
Upvotes: 4
Views: 239
Reputation: 3586
One way is to have both an immutable and a mutable version of every business model object. I wrote an article on that here: http://rickyhelgesson.wordpress.com/2012/07/17/mutable-or-immutable-in-a-parallel-world/
Upvotes: 0
Reputation: 148524
you can set private constructor - so only inside items can create the instance.
Also , you can use the constructor to put readonly Values....
Upvotes: 0
Reputation: 499012
Either make the cached items immutable themselves, or pass through copies of the objects.
Upvotes: 6