Use of Interface vs Class for declaring application constant
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jegan_Govindan
Posted On:   Friday, March 5, 2004 05:02 AM

I want to use some constants through out the application. For that I found two ways to do that as given below 1. We can define constants in a class as public class ConstantClass { public static final String applConstant = "Some Constant"; } and use it ConstantClass.applConstant whereever needed Or 2. We can define an interface as public interface IConstantInterface { String applConstant = "Some Constant"; } and use it IConstantInterface.applConstant Can you pls explain which is the best method to be used in the application and why? Thanks in advance.    More>>
			

I want to use some constants through out the application. For that I found two ways to do that as given below

1. We can define constants in a class as
public class ConstantClass {
public static final String applConstant = "Some Constant";
}

and use it ConstantClass.applConstant whereever needed
Or

2. We can define an interface as
public interface IConstantInterface {
String applConstant = "Some Constant";
}

and use it IConstantInterface.applConstant

Can you pls explain which is the best method to be used in the application and why?
Thanks in advance.

   <<Less

Re: Use of Interface vs Class for declaring application constant

Posted By:   Christopher_Koenigsberg  
Posted On:   Friday, March 5, 2004 07:30 AM

Good question. I had been putting these in interfaces, myself. But then I read in Josh Bloch's great book "Effective Java" that it's better to put them in a class (I don't have the book with me so I can't look up exactly what he says and why...).

About | Sitemap | Contact