ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Implementing Custom Data Bindable Classes: CollectionBase
Subject:   Using objects with more than 1 property
Date:   2004-07-05 21:45:29
From:   dwfresh
This is a great article, however, if I had a products class with 10 properties, and wanted to allow a user to sort on any property, would I have to write 10 different 'AscendingNameSorter' type classes?
ie: AscendingTypeSorter, AscendingManufacturerSorter, etc.

private class AscendingNameSorter : IComparer
{
public int Compare(Object x, Object y)
{
Products.Product p1 = (Products.Product)x;
IComparable ic1 = (IComparable)p1.Name;


Products.Product p2 = (Products.Product)y;
IComparable ic2 = (IComparable)p2.Name;


return ic1.CompareTo(ic2);
}
}


So just write 10 different classes just like this one for each property.
I know there is a much better way, but would love to hear an answer from an expert!


Thanks!


Doug


1 to 2 of 2
  1. Implementing sort for multiple properties
    2005-01-12 15:30:47  Daniel_Odulo [View]

  2. Using objects with more than 1 property
    2004-09-13 16:09:47  jamesstill [View]

1 to 2 of 2