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 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> References: <2eOdnXdWwdSD2HHTnZ2dnUVZ_t6dnZ2d@posted.palinacquisition> 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: 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 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