The Need for Copy Constructors

Writing and using Classes in Dyalog APL
uwejanza
Posts: 19
Joined: Tue Mar 09, 2010 2:01 pm
Location: Nürnberg, Germany

Re: The Need for Copy Constructors

Post by uwejanza »

As far as I need it in my applications, it does work for derived classes.

The ∆CopyFrom and ∆CopyTo properties are implemented in one central base class that I derive from. This base class also implements a MakeMeACloneOf method.
The basic functionality lies in the line ∆CopyTo←SourceObject.∆CopyFrom.

Depending on the degree of privacy you implement in your classes you may find it necessary to have this line in some method in your derived class as well.

If the fields in your object instances contain data values like classic APL variables, everything works fine.
If some of the fields in your class contain (references to) instances of objects or references to namespaces MakeMeACloneOf creates references to the originals. in that case, think twice before use, it may harm your application.

So, to get what my application really needs, some of my derived classes implement their own
MakeMeACloneOf method which after the basic ∆CopyTo←SourceObject.∆CopyFrom do some more sophisticated stuff.
Post Reply