File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface constants - Anti pattern

 
Srinivas Ivaturi
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I heard that we should not declare the constants in Interface to access them in concrete class which is called Anti pattern.

Is it true? If so please let me know what are the other ways where I declare constants and use them

Thanks
Srinivas Ivaturi.
 
Deepak Pant
Ranch Hand
Posts: 446
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declare them in class itself.
(a) You can create Enumeration classes to contain enum type constants. OR
(b) You can have a package level class containing constants to be used across the classes in that package.
(c) Point is that never declare the constants in the Interface. Interface is not meant for this purpose.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic