Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Newbie question on proper use of Interface

Thread view: 
dsh0105@gmail.com - 25 Oct 2005 13:59 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.