Newbie question on proper use of Interface

Discussion in 'Java' started by dsh0105@gmail.com, Oct 25, 2005.

  1. Guest

    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
    , Oct 25, 2005
    #1
    1. Advertising

  2. dwalter Guest

    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.
    dwalter, Oct 25, 2005
    #2
    1. Advertising

  3. Roedy Green Guest

    On 25 Oct 2005 05:59:55 -0700, "" <>
    wrote, quoted or indirectly quoted someone who said :

    >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

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Oct 25, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. THY
    Replies:
    4
    Views:
    624
    Oliver
    Oct 25, 2003
  2. Wildepiet
    Replies:
    0
    Views:
    1,860
    Wildepiet
    Jun 14, 2004
  3. cyberco
    Replies:
    8
    Views:
    487
    cyberco
    Feb 25, 2006
  4. Serena
    Replies:
    4
    Views:
    404
    Cy Edmunds
    Jun 14, 2004
  5. H. Wade Minter
    Replies:
    8
    Views:
    286
    Robin
    Apr 25, 2004
Loading...

Share This Page