Difference between revisions of "Comparison of objects"

From Liberty Eiffel Wiki
Jump to navigation Jump to search
 
Line 17: Line 17:
 
The problem of comparing two objects has to be mastered fairly quickly, for it's a very common problem posed in many applications, if not '''almost all applications'''.
 
The problem of comparing two objects 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 the respective addresses of the two objects in question, 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.
  +
  +
Finally, just to be complete, this part will also discuss the possibility of carrying out a third sort of comparison, [[#is_deep_equal|deep equality]], a comparison uniquely reserved for a very rare family of applications.
 
<div id="EqNeq">
 
<div id="EqNeq">

Revision as of 14:21, 6 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

The problem of comparing two objects 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 the respective addresses of the two objects in question, 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.