Java best practice Interface - subclasses and constants

Posted by Taiko on Programmers See other posts from Programmers or by Taiko
Published on 2014-06-09T06:00:12Z Indexed on 2014/06/09 9:42 UTC
Read the original article Hit count: 200

Filed under:
|

In the case where a couple of classes implements an interface, and those classes have a couple of constants in common (but no functions), were should I put this constant ?

I've had this problem a couple of times.

I have this interface : DataFromSensors that I use to hide the implementations of several sub classes like DataFromHeartRateMonitor DataFromGps etc...

For some reason, those classes uses the same constants. And there's nowere else in the code were it is used.

My question is, were should I put those constants ?

Not in the interface, because it has nothing to do with my API

Not in a static Constants class, because I'm trying to avoid those

Not in a common abstract class, that would stand between the interface and the subclasses, because I have no functions in common, only a couple of constants (TIMEOUT_DURATION, UUID, those kind of things)

I've read best practice for constants and interface to define constants but they don't really answer my question.

Thanks !

© Programmers or respective owner

Related posts about java

Related posts about interfaces