Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Declaring constants... where ? (class or interface)

 
Samuel Pessorrusso
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Currently I'm declaring all constants at an interface (without methods) and when a class need to use a constant, it implements this interface. Is it a good design or it would be bether to create a normal class to store these constants?

Thanks

Samuel
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Samuel,

What you are proposing (often referred to as the "Constant Interface Antipattern") is generally not recommended. JDK 5 introduced The "Static Import" Construct to get around this problem.

Regards, Andrew
 
Samuel Pessorrusso
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the advice!
[ October 04, 2005: Message edited by: Samuel Pessorrusso ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's also worth to think whether the "constants" are really constants. Perhaps some of them would better be put in a properties/preferences file, so that recompilation is not neccessary if one of those "constants" changes.
Cheers
-Barry
 
Samuel Pessorrusso
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Gaunt:
It's also worth to think whether the "constants" are really constants. Perhaps some of them would better be put in a properties/preferences file, so that recompilation is not neccessary if one of those "constants" changes.
Cheers
-Barry


I agree that your point is a good practice but it is out of assignment scope. So I will not implement it . NO MORE WORK!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic