Abstract
In object oriented programming, it is sometimes necessary to copy objects and to compare them for equality or inequality. We discuss some of the issues involved in copying and comparing objects and we address the problem of generating appropriate copying and comparing operations automatically, a service that is not provided by most object oriented languages and environments. Automatic generation appears to be not only desirable, because hand-coding these methods is mechanical and yet error-prone, but also feasible, because the form of the code is simple and largely predictable.
Some languages and some object models presented in the literature do support generic copying and comparing, typically defining separate “shallow” and “deep” versions of both operations. A close examination of these definitions reveals inadequacies. If the objects involved are simple, copying and comparing them is straightforward. However, there are at least three areas in which insufficient attention has been given to copying and comparing complex objects: (1) values are not distinguished from objects; (2) aggregation is not distinguished from association; and (3) the correct handling of linked structures other than trees is neglected. Solving the third problem requires a mechanism built into the language, such as exists in Eiffel. Building such a mechanism without modifying the language requires a language with sufficient reflexive facilities, such as Smalltalk. Even then, the task is difficult and the result is likely to be insecure.
We show that fully automatic generation of copying and comparing operations is not feasible because compilers and other software tools have access only to the structure of the objects and not to their semantics. Nevertheless, it is possible to provide default methods that do most of the work correctly and can be fine-tuned with a small additional amount of hand-coding.
We include an example that illustrates the application of our proposals to C++. It is based on additional declarations handled by a preprocessor.
On leave from the Department of Computer Science and Information Systems, University of Jyväskylä Jyväskylä, Finland
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
Serge Abiteboul and Jan Van den Bussche. Deep equality revisited. In T.W. Ling, A. O. Mendelzon, and L. Vieille, editors, Deductive and Object-Oriented Databases: Fourth International Conference, DOOD’ 95, Singapore, December 4–7, 1995, Proceedings, number 1013 in LNCS, Berlin and Heidelberg and New York, 1995. Springer-Verlag.
Ken Arnold and James Gosling. The Java Programming Language. Addison-Wesley, second edition, 1998.
Grady Booch, James Rumbaugh, and Ivar Jacobson. The Unified Modeling Language: User Guide. Object Technology. Addison Wesley, 1999.
Peter Grogono. Issues in the design of an object oriented programming language. Structured Programming, 12(1):1–15, January 1991.
Peter Grogono and Patrice Chalin. Copying, sharing, and aliasing. In Colloquium on Object Orientation in Databases and Software Engineering (ACFAS’94), Montreal, Quebec, May 1994.
Peter Grogono and Markku Sakkinen. A view and interface generator for C++. Technical report, Department of Computer Science, Concordia University, November 1999.
Sonya E. Keene. Object-Oriented Programming in COMMON LISP. Addison-Wesley, 1989.
Setrag N. Khoshafian and George P. Copeland. Object identity. In Proc. ACM Conf. on Object-Oriented Programming Systems, Languages and Applications, pages 406–416, September 1986.
Bjørn Kirkerud. Object-Oriented Programming with Simula. Addison Wesley, 1989.
John Lakos. Large-Scale C++ Software Design. Professional Computing Series. Addison-Wesley, 1996.
Wilf LaLonde and John Pugh. Complexity in C++: A Smalltalk perspective. J. Object-Oriented Programming, 8(1):49–56, March/April 1995.
Barbara Liskov, Russell Atkinson, Toby Bloom, Eliot Moss, J. Craig Schaffert, Robert Scheifler, and Alan Snyder. CLU Reference Manual. Number 114 in LNCS. Springer-Verlag, Berlin and Heidelberg and New York, 1981.
Barbara Liskov and John Guttag. Abstraction and Specification in Program Development. MIT Press, 1986.
Bruce J. MacLennan. Values and objects in programming languages. ACM SIGPLAN Notices, 17(12):70–79, December 1983.
Ole Lehrmann Madsen, Birger Møller-Pedersen, and Kristen Nygaard. Object-Oriented Programming in the BETA Programming Language. ACM Press/Addison Wesley, 1993.
Bertrand Meyer. Eiffel: the Language. Prentice Hall International, 1992.
Bertrand Meyer. Object-oriented Software Construction. Object Oriented Series. Prentice Hall, second edition, 1997.
Scott Meyers. Effective C++. Addison-Wesley, 1992.
Steven P. Reiss. A Practical Introduction to Software Design with C++. Wiley, 1999.
J. Rumbaugh. Controlling propagation of operations using attributes on relations. In N. Meyrowitz, editor, Proc. ACM Conf. on Object-Oriented Programming Systems, Languages and Applications, pages 285–296, September 1988.
Bjarne Stroustrup. The Design and Evolution of C++. Addison-Wesley, 1994.
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2000 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Grogono, P., Sakkinen, M. (2000). Copying and Comparing: Problems and Solutions. In: Bertino, E. (eds) ECOOP 2000 — Object-Oriented Programming. ECOOP 2000. Lecture Notes in Computer Science, vol 1850. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-45102-1_11
Download citation
DOI: https://doi.org/10.1007/3-540-45102-1_11
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-67660-7
Online ISBN: 978-3-540-45102-0
eBook Packages: Springer Book Archive