Hi all,
I'm writing a program as part of attempt to get a grasp on the Java
language. For the part of the program I need to implement several
rules-based sorting methods to sort an ArrayList.
>From what I understand, this might be a good place to use an Interface.
I create an interface that defines all the methods each sort routine
must implement, then create concrete classes for each of the sorting
methods to be called as needed. Since they will all implement the same
interface, they should be swapable on an as-needed basis (including at
run-time?).
This would also give the added advantage of being able to apply
multiple sort rutines to the say list in any given order.
So my question is: is my logic sound? Is this this (at least one of)
the reasons a person would use an Interface?
Thanks,
David
dwalter - 25 Oct 2005 14:14 GMT
Yes this is one of the reaons you would use an interface, although I
can only think of only one method a sorting interface defines and that
is the sort function. and if your sort routines are correct then
sorting more than once should do nothing.
Roedy Green - 25 Oct 2005 14:53 GMT
>So my question is: is my logic sound? Is this this (at least one of)
>the reasons a person would use an Interface?
You might have a peek at some of my sorts that come with source. see
http://mindprod.com/jgloss/sort.html
or the Java built in sorts. You want to read up on Comparator and
Comparable. They are the only interfaces you need for a sort. You will
just irritate people if you reinvent a Comparator-wheel since they
already have Comparators written to use in Sun sort and Sun
Collections.
see http://mindprod.com/jgloss/comparable.html
http://mindprod.com/jgloss/comparator.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.