Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface constants - Anti pattern

 
Srinivas Ivaturi
Ranch Hand
Posts: 50
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic