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 / May 2005

Tip: Looking for answers? Try searching our database.

What is the reason for putting constants in another class?

Thread view: 
- - 06 May 2005 02:01 GMT
Does anybody know the reason why the constants in
javax.swing.ScrollPaneConstants are put in a separate class instead of
simply putting them inside javax.swing.JScrollPane itself?
Joseph Dionne - 06 May 2005 02:12 GMT
> Does anybody know the reason why the constants in
> javax.swing.ScrollPaneConstants are put in a separate class instead of
> simply putting them inside javax.swing.JScrollPane itself?

They are all gouged in one place, typically public static final, and
accessed as MyClassDefaults.CONSTANT_VALUE.
- - 06 May 2005 02:23 GMT
>> Does anybody know the reason why the constants in
>> javax.swing.ScrollPaneConstants are put in a separate class instead of
>> simply putting them inside javax.swing.JScrollPane itself?
>
> They are all gouged in one place, typically public static final, and
> accessed as MyClassDefaults.CONSTANT_VALUE.

Then how about the constants in java.awt.event.ActionEvent? Why didn't
they put them in ActionEventConstants?  Is it because they only make it
a point to separate them from swing onwards?
Joseph Dionne - 06 May 2005 02:59 GMT
>>> Does anybody know the reason why the constants in
>>> javax.swing.ScrollPaneConstants are put in a separate class instead
[quoted text clipped - 6 lines]
> they put them in ActionEventConstants?  Is it because they only make it
> a point to separate them from swing onwards?

Perhaps Java is showing its age?  As use in a language increases,
drawing greater feed back, "proper" syntax evolves addressing common
complaints.  But, Java tries to be "upwards" portable.  Changing AWT at
1.3 or later would break every application developed prior.  That is
what Microsoft does with annoying regularity.  Sun changes API structure
breaking upward compatibility, i.e. depreciated notices, but gives
developers time to update source code while allowing them up use new
features in new product.

Joseph
Daniel Sjöblom - 06 May 2005 03:21 GMT
> Does anybody know the reason why the constants in
> javax.swing.ScrollPaneConstants are put in a separate class instead of
> simply putting them inside javax.swing.JScrollPane itself?

In this particular case, notice that ScrollPaneConstants is an
interface. Thus, by implementing ScrollPaneConstants in a class one can
write MY_FOO_CONSTANT instead of ScrollPaneConstants.MY_FOO_CONSTANT to
refer to some variable. In java 1.5, there is a facility called static
import that allows one to omit the class name without resorting to this
hack.

Signature

Daniel Sjöblom
Remove _NOSPAM to reply by mail

Andrew McDonagh - 06 May 2005 08:18 GMT
>> Does anybody know the reason why the constants in
>> javax.swing.ScrollPaneConstants are put in a separate class instead of
[quoted text clipped - 6 lines]
> import that allows one to omit the class name without resorting to this
> hack.

And yet we should keep in mind that interfaces that define constants,
has been shown to be an anti-pattern.
Wibble - 07 May 2005 03:11 GMT
I hate this pattern.  You put a pile of constants
in a class, use them globally, all the consumers
refactor away and you end up with a file full of
things nobody uses or knows what they're for, but
everyone is afraid to touch.

>>> Does anybody know the reason why the constants in
>>> javax.swing.ScrollPaneConstants are put in a separate class instead
[quoted text clipped - 9 lines]
> And yet we should keep in mind that interfaces that define constants,
> has been shown to be an anti-pattern.


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.