Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10851

Re: Generics ?

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Generics ?
Date Sun, 18 Dec 2011 08:17:33 -0800 (PST)
Organization http://groups.google.com
Lines 31
Message-ID <539021.307.1324225053282.JavaMail.geo-discussion-forums@prmw6> (permalink)
References <jcem2m$gbm$1@dont-email.me> <ag5me7h7pph1d4n2b05uvgump03dp7ig0t@4ax.com> <jchb74$n8m$1@dont-email.me> <2eOdnXdWwdSD2HHTnZ2dnUVZ_t6dnZ2d@posted.palinacquisition> <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>
Reply-To comp.lang.java.programmer@googlegroups.com
NNTP-Posting-Host 173.164.137.213
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
X-Trace posting.google.com 1324225172 10209 127.0.0.1 (18 Dec 2011 16:19:32 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Sun, 18 Dec 2011 16:19:32 +0000 (UTC)
In-Reply-To <yumdnduue4YXJnDTnZ2dnUVZ_g-dnZ2d@westnet.com.au>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.213; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
User-Agent G2/1.0
X-Google-Web-Client true
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10851

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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