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 / JavaBeans / January 2005

Tip: Looking for answers? Try searching our database.

How to provide a reasonable default without a no-parameter-constructor?

Thread view: 
Christian Schlichtherle - 24 Jan 2005 06:03 GMT
Hi everyone,

I am pretty new to JavaBeans, so please excuse the question: How do I
provide a blue print for the state of a JavaBean when a nullary constructor
just isn't adequate? Can this be done at all or is the provisioning of a
nullary constructor a MUST for a JavaBean to be a JavaBean?

(If this text sounds confused then that's only because its a reflection of
my mind :-)

Regards,
Christian
John C. Bollinger - 24 Jan 2005 13:39 GMT
> Hi everyone,
>
[quoted text clipped - 5 lines]
> (If this text sounds confused then that's only because its a reflection of
> my mind :-)

In some sense, a nullary constructor _must_ be sufficient.  That is to
say, in the most general sense you must assume that bean instances will
be initialized by invocation of a nullary constructor (and no other).
Bean classes are required to have one, and it is poor practice and will
cause you problems if that constructor does not leave the new instance
in a consistent, well-defined state.

With that out of the way, there are two non-exclusive possibilities:

1) Refactor your bean into two or more beans.  It is often the case when
a class has complex initialization requirements that the class itself is
too broad in scope.

2) Define class-wide defaults by use of static methods and variables.
This is bit of a kludge, and it has potential to get you into trouble,
but it can be made to work.  The nullary constructor then uses the class
methods and variables to help initialize new instances.

John Bollinger
jobollin@indiana.edu


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.