I have a class that is backed by a double value, and I am wondering about accessor method names that preserve abstraction. Based on my experience in Java, there seems to be at least two precedents:toDouble(), which mirrors toString()doubleValue(), similar to Double.doubleValue() and BigInteger.doubleValue()I need access to this value to perform some computations. Would it be most appropriate to return a double value as I've mentioned, or provide public multiply(), add(), etc. methods?Is there any common practice or precedent for a class used in this way?
Naming convention for getting the primitive backing a type?
java;naming;coding standards
Is there any documented preference, in Java, for either of these conventions?The preference is that the end user has no idea what the backing primitive is for your type. This is encapsulation at its essence.Now, if your object exposes an interface to get a double (regardless of what the backing datatype is), either because you're serializing your object, or because it makes sense to provide that interface, then do so. But the naming convention needs to specifically focus on what the data is (be a serialized form, seconds since unix epoch, etc.) not what it does (serve as the implementation details of your object).  