> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 12 lines]
> The first. Google for ‘prefer interface over implementation’ or some
> rule in that line.
Exception: you need some methods specific to the class (for example
LinkedLists's removeFirst()).
robert
Lew - 24 May 2007 13:16 GMT
Peppy schreef:
>>> List <String> list = new ArrayList <String> ( );
>>> ArrayList <String> list = new ArrayList <String> ( );
>> The first. Google for ‘prefer interface over implementation’ or some
>> rule in that line.
"Use the most general type appropriate to your algorithm."
If List is too general, use the second, otherwise prefer the first as Robert said.
One advantage of the first is that you can very easily refactor the
declaration, e.g.,
List <String> stuff = new TreeList <String> ();
Side note: "list" is a terrible name for a variable, especially if its type is
not "List", as in the second case. Either way it says little to nothing about
the interpretation of the variable.

Signature
Lew
Hendrik Maryns - 24 May 2007 17:23 GMT
Robert Klemme schreef:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
[quoted text clipped - 15 lines]
> Exception: you need some methods specific to the class (for example
> LinkedLists's removeFirst()).
Well, no, then you probably want to declare the variable of the type
Deque. LinkedList implements a lot of interfaces. I have used it as a
Queue as well.
H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html