2 Replies Latest reply on Dec 3, 2003 6:49 PM by Vishal Sharma

    Design Question/Say Best Java Practice.

    Vishal Sharma Expert

      Hi All,
      I have been recently reading about some recent best practices in Java and came across one interesting arctilcle on where to declare yr global constants.

      Two Approaches are suggested.
      1. The conventional practice is to declare them in Interface.
      2. To declare them in a Final Class.

      Can aynyone reflect some of thier viewpoints on this one please.

      Note : I know this is not an J2EE specific question, but this practice is used heavily in J2EE Development environment .


        • 1. Re: Design Question/Say Best Java Practice.
          Jon Barnett Master

          Pragmatically, I would say it depends on usage and organisation.

          Suppose that the constants are used more by "users" of the implementation rather than the implementors, you would put it in the interface because you are using the interface to "isolate" the user-developer from the implemented class. Otherwise, you may not want to "expose" these constants and keep it with the final or implemented class - this is only a physical packaging distinction.

          If you aren't using an interface, you need to decide on what is the most relevant class related to the global constants.

          There are no absolutes, but if you are using interfaces it probably makes more sense to go with the interface (except if those who use the interface don't use the global constants).


          • 2. Re: Design Question/Say Best Java Practice.
            Vishal Sharma Expert

            Appreciate yr views here.
            Thanks Jonlee.