Re: Generics ?
Qu0ll wrote:
Daniel Pitts wrote:
FWIW, you probably shouldn't be extending JList anyway. You should be
implementing ListModel and/or adding listeners to a JList. Pretty much the
only Swing "J*" class you ever really need to extend is JComponent.
But what if you want a special type of JList or JPanel etc. that you can
just drop in wherever a JComponent would be accepted in multiple places in
your program or other programs? How can you avoid subclassing in those
cases?
"Prefer composition to inheritance" does not mean "Use composition instead of
inheritance".
You have to weigh the substantial cost of extending a type over the lower cost
of composing it to see if the benefits justify the expense.
In some cases you actually are not adding any functionality to a candidate
parent type. You think you are, but if all the action happens in 'add()'-style
method (as is often the case with proposed inheritance factoring) in your
derived class with no actual *functional* changes from the parent, then you are
not really inheriting, you're just using 'extends' improperly.
As with everything else in programming, you have to use advice judiciously, not
follow it superstitiously.
Without a code example (SSCCE) we cannot tell if your hypothetical situation
calls for inheritance or not. It's just too broadly stated.
--
Lew