On Friday, 28 November 2014 at 08:31:26 UTC, bearophile wrote:
Uranuz:

Same situation happens when I assign reference data to properties.

Someone has suggested to solve this problem with an attribute, like "owned", that forbids to return mutable reference data owned by a class/struct instance.

Bye,
bearophuile

Yes. Problem is even if you have property that controls correct assignment. If you have getter that returns mutable reference type and you try to access some fields of it or apply index operator (for arrays or AA) *host* cannot control corectness of these assignments or cannot react to these changes (in order to do some changes in model).

The way I see is to create my own type of Array for this that can notify *host object* about changes so it could refresh the model or do some checks.

Another way is to write interfaces in a way so we cant't escape uncontrolled references to mutable data.

What do you think of it? Is there any patterns that could help to solve such problems?

I think that writing your own type every time when you need to enforce consistency and safety is not very good))

Reply via email to