dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Beginner
May 16, 2018

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Having a Global Configuration, Parameters, Constants Class

Using one class or interface that contains all kinds of constants used during the application may not be the best solution. These constants are unrelated with each other, the only thing that they have in common is the interface or the class and the reference to this class will contaminate many other unrelated components of the application.

What if you want to share some classes between a server and a remote client? Or later extract a component and use it in another application? This class has created a dependency between unrelated components and this limits reuse and loose coupling. You should never place constants across component boundaries, this is an exception only if the component is a library, and an explicit dependency is wanted.

public interface Constants {
   String version = "1.0";
   String dateFormat = "dd.MM.yyyy";
   String configurationFile = ".apprc"; 
   int maxNameLength = 32;
   String someQuery = "SELECT * FROM ...";
}
Octavia Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date