• 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

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

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic