Is it a bad practice to have an interface to define constants?
Posted
by
FabianB
on Programmers
See other posts from Programmers
or by FabianB
Published on 2011-02-19T01:55:31Z
Indexed on
2011/02/19
7:32 UTC
Read the original article
Hit count: 186
java
|best-practices
I am writing a set of junit test classes in java. There are several constants, for example strings that I will need in different test classes. I am thinking about an interface that defines them and every test class would implement it.
The benefits I see there are:
- easy access to constants: "MY_CONSTANT" instead of "ThatClass.MY_CONSTANT"
- each constant defined only once
Is this approach rather a good or bad practice? I feel like abusing the concept of interfaces a little bit.
You can answer generally about interfaces/constants, but also about unit tests if there is something special about it.
© Programmers or respective owner