The Proceedings of the Information Systems Education Conference 2005: §2554    Home    Papers/Indices    prev (§2553)    Next (§2555)
Fri, Oct 7, 3:30 - 3:55, Senate B     Paper (refereed)
Recommended Citation: Dollinger, R.  A Solution to Mixed-type Comparisons in C# .NET.  In The Proceedings of the Information Systems Education Conference 2005, v 22 (Columbus OH): §2554. ISSN: 1542-7382. (A later version appears in Information Systems Education Journal 4(36). ISSN: 1545-679X.)
CDpic

A Solution to Mixed-type Comparisons in C# .NET

thumb
Refereed11 pages
Robert Dollinger    [a1] [a2]
Department of Mathematics and Computing
University of Wisconsin Stevens Point    [u1] [u2]
Stevens Point, Wisconsin, USA    [c1] [c2]

Overriding Equals() in order to provide meaningful semantics to object comparisons, turns out to be quite a challenging task, especially when involving objects at different levels of a class hierarchy. One need to reconcile the requirements of the equals contract with the legitimate expectations of programmers of being able to meaningfully compare objects of different types. Langer&Kreft (Langer, 2002b) provided an implementation of equality checks for Java class hierarchies where they use a recursive navigation method that performs the non-trivial task of navigating up and down in the inheritance tree in order to make sure that objects on different levels or even on different branches of the inheritance tree are compared correctly. In this paper we first present a generalized implementation of the navigation method by using reflection and late binding techniques available in C# .NET. In this implementation navigation is still using recursion very much like the one in (Langer, 2002b). A non-recursive version of the navigation method is also given; this later version is more efficient and easier to understand. The generalized implementation of the navigation method is class independent and, as a result, one can factor it out to the hierarchy's root class. If it would be implemented in the very top class of the .NET hierarchy, the Object class, this would simply make mixed-type equality comparisons generally available by requiring classes to implement some sort of field comparing method thus defining the specific equality semantics, instead of struggling to override the Equals() method.

Keywords: : equals contract, mixed-type comparisons, reflection, late binding

Read this refereed paper in Adobe Portable Document (PDF) format. (11 pages, 654 K bytes)
Preview this refereed paper in Plain Text (TXT) format. (36 K bytes)

CDpic
Comments and corrections to
webmaster@isedj.org