|
"Alon " <utzly@bgu.ac.il> wrote in message <j4hu7i$3mj$1@newscl01ah.mathworks.com>...
> Hi,
>
> I have a collection which is of class 'containers.Map'. It contains objects of a certain class which I created.
> I can set this collection to be 'global' and share it between the main function and all sub functions. But I didn't find a way to do the same with the objects that this collection refers to. So, what ever change I make to one of the objects I have to re-enter it to the collection to keep it shared.
>
> Is there a simple way to make the objects 'global' as well as the collection?
I don't think it's a question of global vs. local.
It sounds as if you are working with value objects, and that you are assigning an object from the collection to a variable, and then changing one or more property values. This would mean that you have actually changed a copy of the object, so naturally you then have to enter the copy into the collection in place of the original, otherwise you won't be changing the collection itself.
This would not happen with handle objects; instead you'd store a handle in the collection and update the one and only copy of the object via the handle. You could change your class to inherit from handle, but you should do this only if it makes architectural sense for your broader application to deal with handle objects instead of value objects.
|