"Gavin Kistner" <com> schrieb im Newsbeitrag
That ain't going to be solved easily: What you really want is to mark a
*graph* of instances to be unmodifiable, i.e., if any instance in your
collection returns some member, that in turn must not be modified, too
You could try to use Delegator and add a state variable "modifyable" which
is evaluated by all modifying methods. The hard part here is to
automatically know which methods are modifying methods...
If you've got enough mem you can clone the whole object graph starting
with the collection with the typical Marshal idiom "Marshal.load(
Marshal.dump( collection ) )". But if the collection is big, this will
burn a lot of mem and might take some time.
If you follow discussions in C++ ng's about "const" and think a while
about the matter than you'll discover a lot of annoying things that happen
once you start to try to differentiate const and mutable instances. For
example, consider lazy intialization: an instances state might look the
same from the outside (hence it could be regarded as const), while the
real state does change in certain situations. Now, is this instance const
or not? etc.
I'd say, don't invest too much time into this and rather doent which
parts of the application are allowed to do modifications and which are