Re: Passing reference data to class and incapsulation

2014-11-28 Thread bearophile via Digitalmars-d-learn
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

Re: Passing reference data to class and incapsulation

2014-11-28 Thread mark_mcs via Digitalmars-d-learn
Same situation happens when I assign reference data to properties. I can check or do something with data at the moment of assignment, but I can't control that someone will modify using initial reference from outside. So do you copy reference data in constructors or properties? Should it be? Or

Re: Passing reference data to class and incapsulation

2014-11-28 Thread Daniel Kozák via Digitalmars-d-learn
V Fri, 28 Nov 2014 06:19:37 + Uranuz via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: In D we a several data types which are passed by reference: dynamic arrays, associative arrays. And sometimes we need to pass these reference data to class instance to store it inside.

Re: Passing reference data to class and incapsulation

2014-11-28 Thread Uranuz via Digitalmars-d-learn
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

Re: Passing reference data to class and incapsulation

2014-11-28 Thread mark_mcs via Digitalmars-d-learn
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

Passing reference data to class and incapsulation

2014-11-27 Thread Uranuz via Digitalmars-d-learn
In D we a several data types which are passed by reference: dynamic arrays, associative arrays. And sometimes we need to pass these reference data to class instance to store it inside. One of the principles of object-oriented programming is incapsulation. So all class data should be only