Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem Interface/Abstract/Collections

 
stefan bisang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Cheers
Stefan

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


 
stefan bisang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there

I've solved the problem, did the following:

Interface:


and then I've created an abstract class aList:


and Class ListOne:


and Class ListTwo



Is that a good solution?

Thanks

Stefan
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic