I am making a simple program that supports a list of numbers, and I want the list to also have a name. Which one works best: do I include my ArrayList list class or include an ArrayList element? In both cases, there would of course be a "name", a member of String.
The first approach means that I only need to implement getter and setter for the name, but I think this binds my class too much to a specific implementation? For example, if I wanted to use Vector, then I would have to change the code everywhere.
The second approach will simplify the implementation change, but, of course, now it is becoming quite annoying, since I have to implement a wrapper package.
I read SO posts regarding inheritance and composition, and since my list is a type of ArrayList, I am leaning towards the first approach. However, are there any differences in the discussion because I am extending the Collection class and extending the general class? Or am I thinking too much about this?
source
share