Difference between revisions of "Comparison of objects"
Line 17: | Line 17: | ||
How to compare two objects is a problem that has to be mastered fairly quickly, for it's a very common problem posed in many applications, if not '''almost all applications'''. |
How to compare two objects is a problem that has to be mastered fairly quickly, for it's a very common problem posed in many applications, if not '''almost all applications'''. |
||
− | In Eiffel, as in most object-oriented languages, there are several ways to compare two objects, be it to compare |
+ | In Eiffel, as in most object-oriented languages, there are several ways to compare two objects, be it to compare their respective addresses or be it to compare the information contained in each of the two objects. In other words, using Eiffel terminology, one must choose whether to use [[#EqNeq|the predefined = operator]] or the redefinable [[#is_equal|<TT>is_equal</TT>]] routine. |
The Eiffel language aims to avoid, as far as possible, mistakes caused by inattention; so it isn't possible to compare any type of expression with any other type of expression. The [[#ValidComparison|validity of a comparison]] will be detailed below. |
The Eiffel language aims to avoid, as far as possible, mistakes caused by inattention; so it isn't possible to compare any type of expression with any other type of expression. The [[#ValidComparison|validity of a comparison]] will be detailed below. |
Revision as of 02:06, 7 September 2005
*** *** Please if you read French, translate the corresponding page using the French version as a model. *** If you decide to translate this page, start to add here a *** note in order to avoid multiple *** translators. *** Please, check also our Author guidelines first ! *** Thanks in advance. *** Colnet 11:59, 6 Sep 2005 (CEST) *** *** Well, I've made a small start, but others are welcome (as far as I'm concerned) to contribute. *** I'm having fun translating it, but this could take some days! *** Peter Gummer 6 Sep 2005
Comparing two objects
How to compare two objects is a problem that has to be mastered fairly quickly, for it's a very common problem posed in many applications, if not almost all applications.
In Eiffel, as in most object-oriented languages, there are several ways to compare two objects, be it to compare their respective addresses or be it to compare the information contained in each of the two objects. In other words, using Eiffel terminology, one must choose whether to use the predefined = operator or the redefinable is_equal routine.
The Eiffel language aims to avoid, as far as possible, mistakes caused by inattention; so it isn't possible to compare any type of expression with any other type of expression. The validity of a comparison will be detailed below.
Finally, just to be complete, this part will also discuss the possibility of carrying out a third sort of comparison, deep equality, a comparison uniquely reserved for a very rare family of applications.