• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Poobhathy Kannan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • 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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
Roshan Lal
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • 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
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!