Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class or Interface for Constants

 
Bhagat Singh Rawat
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.

You will now have seen, class is the answer to your problem
 
Bhagat Singh Rawat
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic