devxlogo

Having a Global Configuration, Parameters, Constants Class

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 ...";}
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist