File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Problem Interface/Abstract/Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem Interface/Abstract/Collections" Watch "Problem Interface/Abstract/Collections" New topic

Problem Interface/Abstract/Collections

stefan bisang

Joined: Jun 03, 2010
Posts: 3
Hey there

I'm working on a exercise and got the following problem:

I wrot this Interface:

and I've implemented this interface in Class ListOne:

At this point, everything seems fine and okay

Next Step:
I have to implement the a Class ListTow with an LinkedList instead of an ArrayList and of course I should reuse as much as possible code. I know that I have to refactor it :-), but what is now the approach? Should I create an abstract Class for ListOne and ListTwo or how should i proceed?

Thanks a lot for any hints


Ps: sorry for my bad english, but I'm not a native english speaker

stefan bisang

Joined: Jun 03, 2010
Posts: 3
Hey there

I've solved the problem, did the following:


and then I've created an abstract class aList:

and Class ListOne:

and Class ListTwo

Is that a good solution?


Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
If it works then it's a "Good Thing" however you should note that index based access of LinkedList elements are not as efficient as index based access of ArrayList elements, so your algorithms for the LinkedList based implementation will not be as performant. Iterator based algorithms might be better,

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
I agree. Here's the link:
subject: Problem Interface/Abstract/Collections
It's not a secret anymore!