aspose file tools
The moose likes Java in General and the fly likes Placing widely used constants in an interface or in a class. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Placing widely used constants in an interface or in a class." Watch "Placing widely used constants in an interface or in a class." New topic
Author

Placing widely used constants in an interface or in a class.

Poobhathy Kannan
Ranch Hand

Joined: May 26, 2004
Posts: 94
Which way could be the best choice of followings?

1. Placing widely used constants in an Interface
2. Placing widely used constants in a Class


http://learnertobeginner.blogspot.com/
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I doubt if there would be any performance implications one way or the other. Placing constants in an Interface is supposedly frowned upon, but again I can't really see a reason why.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Roshan Lal
Ranch Hand

Joined: Nov 13, 2001
Posts: 64
Originally posted by Paul Sturrock:
I doubt if there would be any performance implications one way or the other. Placing constants in an Interface is supposedly frowned upon, but again I can't really see a reason why.


It is frowned upon basically for not using Interfaces for its intended purpose, but for side effect.
That is for convenience it provides that you don't have to
fully qualify the constants as compared to if they were in a class.

Typically we use interfaces so that the clients can work with interfaces rather than the classes implementing them, giving the flexibility of changing the implementations without having to change client code.

HTH

-Roshan
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Placing constants into interfaces is not was is frowned upon, but inheriting them from an interface to use the constants inside a class is.

This is not a performance related, though, so I'm moving to Java in General (intermediate). It is a quite frequently asked question, by the way - a search should give you many interesting discussions on the topic.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Placing widely used constants in an interface or in a class.
 
Similar Threads
Variables declared in upper case
Inner Classes
Implementing interface with no methods
Interface constants - Anti pattern
What's the best way to declare global constants?