• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class or Interface for Constants

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
reply
    Bookmark Topic Watch Topic
  • New Topic