Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10851
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Generics ? |
| Date | 2011-12-18 08:17 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <539021.307.1324225053282.JavaMail.geo-discussion-forums@prmw6> (permalink) |
| References | (4 earlier) <jcimia$9dh$1@dont-email.me> <jcioh3$k6d$1@dont-email.me> <jciqaq$ujj$1@dont-email.me> <PKeHq.20143$c27.3382@newsfe22.iad> <yumdnduue4YXJnDTnZ2dnUVZ_g-dnZ2d@westnet.com.au> |
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
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-15 21:48 -0800
Re: Generics ? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-15 22:03 -0800
Re: Generics ? Tassilo Horn <tassilo@member.fsf.org> - 2011-12-16 08:30 +0100
Re: Generics ? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-16 00:08 -0800
Re: Generics ? Roedy Green <see_website@mindprod.com.invalid> - 2011-12-16 02:10 -0800
Re: Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-16 22:01 -0800
Re: Generics ? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-16 23:30 -0800
Re: Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-17 10:20 -0800
Re: Generics ? markspace <-@.> - 2011-12-17 10:54 -0800
Re: Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-17 11:25 -0800
Re: Generics ? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-12-17 21:20 -0800
Re: Generics ? "Qu0ll" <Qu0llSixFour@gmail.com> - 2011-12-18 21:08 +1100
Re: Generics ? Lew <lewbloch@gmail.com> - 2011-12-18 08:17 -0800
Re: Generics ? markspace <-@.> - 2011-12-18 08:43 -0800
Re: Generics ? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-17 11:33 -0800
Re: Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-17 11:40 -0800
Re: Generics ? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-12-17 11:47 -0800
Re: Generics ? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-12-17 15:13 -0500
Re: Generics ? Roedy Green <see_website@mindprod.com.invalid> - 2011-12-17 02:46 -0800
Re: Generics ? "John B. Matthews" <nospam@nospam.invalid> - 2011-12-17 11:18 -0500
Re: Generics ? Knute Johnson <nospam@knutejohnson.com> - 2011-12-17 11:16 -0800
csiph-web