Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2008

Tip: Looking for answers? Try searching our database.

Swing and ‘prefer delegation over inherit ance’

Thread view: 
Hendrik Maryns - 07 Apr 2008 14:48 GMT
Reading books about software engineering and design patterns, I adopted
the axiom ‘prefer delegation over inheritance’.  However, I see that the
Swing tutorials recommend to inherit from JFrame.  The examples do it as
well, and in fact, a lot of apps I see do this.

Is there a reason for this, or is this just old-fashioned thinking?  Am
I missing something?  My app which *has* a JFrame works just fine.

H.
Signature

Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

RedGrittyBrick - 07 Apr 2008 17:39 GMT
> Reading books about software engineering and design patterns, I adopted
> the axiom ‘prefer delegation over inheritance’.  However, I see that the
> Swing tutorials recommend to inherit from JFrame.  

Are you sure? where?

http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html
makes no such recommendation that I can see, the example has the class
contain a JFrame rather than extend it.

> The examples do it as well,

A lot of Sun's examples which I recall from when learning Swing, used a
CreateAndShowGUI() method which instantiates a JFrame directly.

> and in fact, a lot of apps I see do this.
>
> Is there a reason for this, or is this just old-fashioned thinking?  Am
> I missing something?  

I guess it is mostly old-fashioned thinking, some of the examples must
have been around a long time, with only minor changes. I expect some
examples, when illustrating some subject other than JFrame usage, extend
JFrame merely to reduce the linecount?

My understanding of the collected wisdom here is: just because two
JFrames contain different collections of widgets doesn't make them
different types of JFrame - at least not to the extent that you'd be
justified in subclassing JFrame.

> My app which *has* a JFrame works just fine.

All mine do too nowadays.

Signature

RGB

Arne Vajhøj - 08 Apr 2008 01:23 GMT
> Reading books about software engineering and design patterns, I adopted
> the axiom ‘prefer delegation over inheritance’.  However, I see that the
[quoted text clipped - 3 lines]
> Is there a reason for this, or is this just old-fashioned thinking?  Am
> I missing something?  My app which *has* a JFrame works just fine.

As with so many other patterns, then you should only apply it when
appropriate.

I don't think JFrame is an obvious fit for that pattern.

Both extending and composing JFrame are frequently used.

And frequently discussed.

See http://forums.java.net/jive/message.jspa?messageID=224388 as
an example.

Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.