The Need for Copy Constructors

Writing and using Classes in Dyalog APL

Re: The Need for Copy Constructors

Postby uwejanza on Tue May 24, 2011 4:22 pm

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.
Posts: 19
Joined: Tue Mar 09, 2010 2:01 pm
Location: Nürnberg, Germany


Return to Object Oriented Programming

Who is online

Users browsing this forum: No registered users and 1 guest