
Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
> You can still extend JFrame. That doesn't change. However, needlessly
> extending classes has always been a terrible practice and remains so.
>
> Tom Hawtin
Tom:
I don't disagree but I often compare my code to code I see on these
lists and in books and think that I don't extend enough classes. I
participated in another thread the other day concerning getters and
setters. A large part of the reason for them being protection when the
class is extended. I can understand a different view for API
development but production code, at least most of the code I've written,
will never be extended. Extending classes several times reminds me of a
discussion I had with a fellow I was working for several years ago. We
were writing some large C programs and he told me that it was not
considered good practice to use more than 5 levels of indirection.

Signature
Knute Johnson
email s/nospam/knute/
Thomas Hawtin - 25 May 2006 20:45 GMT
>> You can still extend JFrame. That doesn't change. However, needlessly
>> extending classes has always been a terrible practice and remains so.
> I don't disagree but I often compare my code to code I see on these
> lists and in books and think that I don't extend enough classes. I
There's an awful lot of bad books out there. The vast majority of code
is appalling.
> participated in another thread the other day concerning getters and
> setters. A large part of the reason for them being protection when the
> class is extended. I can understand a different view for API
Really?
> development but production code, at least most of the code I've written,
> will never be extended. Extending classes several times reminds me of a
That doesn't matter. The fact that it extends a leaf class unnecessarily
is good enough reason for it to be bad code.
> discussion I had with a fellow I was working for several years ago. We
> were writing some large C programs and he told me that it was not
> considered good practice to use more than 5 levels of indirection.
Take it one level at a time.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Oliver Wong - 26 May 2006 20:31 GMT
> Extending classes several times reminds me of a discussion I had with a
> fellow I was working for several years ago. We were writing some large C
> programs and he told me that it was not considered good practice to use
> more than 5 levels of indirection.
Why the magic number 5?
The heuristic I usually use is to ask myself if class A has an "IS-A
relationship" with class B. That is, whereever anyone uses class B, would it
make sense to use class A instead? If so, then A should extend B. If not,
then not.
So when I have code like "public class MyApp extends JFrame", I ask
myself, does it really make sense that where ever a JFrame could be used, I
could give a MyApp instead? The answer is usually no. MyApp *USES* a JFrame
in its implementation, but it is not, itself, a JFrame.
- Oliver