Why ArrayList need List interface?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: Why ArrayList need List interface?

  1. #1
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    150

    Why ArrayList need List interface?

    Why ArrayList need List interface?

  2. #2
    Join Date
    Oct 2005
    Posts
    40

    Question

    My question is, In your opinion, why ArrayList should not use List Interface?

  3. #3
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    150
    The following still workable right?

    ArrayList list = new ArrayList();

  4. #4
    Join Date
    Oct 2005
    Posts
    22
    Please be clear of your question. i am not able to understand what the question can you please explain it and what kind of answer are you expecting.

    Thanks

  5. #5
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    150
    My question is very easy. Why Sun expert develop List interface for ArrayList?

  6. #6
    Join Date
    Sep 2005
    Location
    istanbul / Turkey
    Posts
    133
    when you need a collection , there are some candidates.
    ( they differ in implementation )
    each of them has some strong and weak points.
    you make a decision depends on your problem
    and choose one..
    for details you can look at a data structures and algorithms book.

    imagine this method:

    ArrayList myMethod( ArrayList l ){
    ...
    }

    there may be a lot of methods in your code.
    and if you change you decision after a time ?
    ( switch ArrayList to LinkedList )

    but this way, no change required:

    List myMethod( List l ){
    ...
    }

  7. #7
    Join Date
    Oct 2005
    Posts
    40

    Lightbulb

    See, interfaces are created for better software design and engineering. ArrayList is a type of List and so is LinkedList. List interface defines common methods that has to be implemented by a concrete List data strucuture.

    Say your software requires to use Lists but there are many types of lists, doubly, array based etc. It might be possible that some implentation is specifically best for problem in hand. Also it might be possible that later on you come up with your own List implementation which is better than one provided by library(although chances for this are slim).

    So in your code you can simply pass something like this

    someFunction( List list )

    and you can call someFuntion with any class object which implements List interface.

    I doubt I have answered your question, but think advantage of having List interface from design point of view.

    Regards,
    Mohit

  8. #8
    Join Date
    Oct 2005
    Posts
    22
    Mohit has explained it clearly but still if you don't understand Let me explain in a more better sense. More technical.

    Suppose you want to write a program which takes input a list of numbers. When I meant list of numbers i mean many numbers which your program accepts and does some logic.

    Please concentrate on the numbers you are passing. I said you accepting it as an input.
    and so you are not the one who is going to call the method or the program.some other person, say XXX is going to call. XXX knows that he has to pass many numbers to your program, but does not know what your program does,But he know that the he has to pass many programs and he will required output.

    Now how is he going to sent it.He can send it as a ArrayList,Array,or Linked List or Vector whatever it maybe,Your program should work.

    And the second reason is to act as a proxy for the List Collections.

    Hope by now you should have understoood it.Thanks
    G.Rajasekhar

  9. #9
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    150

    Understand. Thanks all.

    Understand. Thanks all.

Similar Threads

  1. Replies: 10
    Last Post: 05-15-2005, 07:14 AM
  2. Replies: 6
    Last Post: 03-27-2002, 09:13 PM
  3. ListBot Going Out of Business
    By Larry Rebich in forum vb.announcements
    Replies: 1
    Last Post: 06-28-2001, 02:22 PM
  4. Replies: 0
    Last Post: 12-15-2000, 03:58 PM
  5. Interface leaks in C#?
    By Kevin Burton in forum .NET
    Replies: 12
    Last Post: 10-09-2000, 11:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center