jQuery in Action, 3rd edition
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Interface constants - Anti pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Interface constants - Anti pattern" Watch "Interface constants - Anti pattern" New topic

Interface constants - Anti pattern

Srinivas Ivaturi
Ranch Hand

Joined: Jan 28, 2003
Posts: 50
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

Srinivas Ivaturi.
Deepak Pant
Ranch Hand

Joined: Feb 13, 2004
Posts: 446
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Interface constants - Anti pattern
It's not a secret anymore!