aspose file tools*
The moose likes Beginning Java and the fly likes Class or Interface for Constants Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class or Interface for Constants" Watch "Class or Interface for Constants" New topic
Author

Class or Interface for Constants

Bhagat Singh Rawat
Ranch Hand

Joined: Apr 04, 2009
Posts: 93
Hi Ranchers,

How does it make difference if I create an Interface or Class for Constants in an application?

for example:


public interface AppConstants {
public static final String REQUEST_ATTR = "request";
public static final String SESSION_ATTR = "session";
........
........
........
}

---------- OR --------------------


public class AppConstants {
public static final String REQUEST_ATTR = "request";
public static final String SESSION_ATTR = "session";
........
........
........
}

Please share your's thoughts.


Brainbench Java 2.0 Fundamentals, J2EE 1.4
http://www.brainbench.com/transcript.jsp?pid=8192792
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
I Googled for "constant interface antipattern" and got this. Open it, use ctrl-F "constant" and you will see the answer to your question.
Bhagat Singh Rawat
Ranch Hand

Joined: Apr 04, 2009
Posts: 93
Campbell Ritchie wrote:I Googled for "constant interface antipattern" and got this. Open it, use ctrl-F "constant" and you will see the answer to your question.


Thank you very much Campbell !!! much appreciate it
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
You're welcome.

You will now have seen, class is the answer to your problem
Bhagat Singh Rawat
Ranch Hand

Joined: Apr 04, 2009
Posts: 93
Campbell Ritchie wrote:You're welcome.

You will now have seen, class is the answer to your problem



Yeah!!!

Static imports - a handy way of simplifying code and avoiding interfaces full of constants
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class or Interface for Constants