commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luc Maisonobe <>
Subject [math] formatting composite objects
Date Sat, 26 Jul 2008 09:09:39 GMT

I am writing a new Vector3DFormat class in the spirit of the
ComplexFormat class for input/output.

Since some parts are common (parsing one component, handling locales), I
have extracted a CompositeFormat base class from ComplexFormat and will
use it as the base class for Vector3D and perhaps for future other classes.

I see that the current ComplexFormat class provides two getInstance()
static methods whose javadoc is: "Returns the default complex format for
the current locale". The instance returned is *not* a singleton, it is
rebuilt each time but the javadoc doesn't says it. Since the class is
not immutable (there are set methods), it may lead to surprising results
to users.

I see two options here:
 1) We keep a mutable class, and either we replace the two getInstance()
    static methods by constructors or we rename them createInstance()
 2) We change the class to immutable and we remove the set methods

My preference is 2). I don't like mutable objects, especially for a low
level library which can be reused differently from various other middle
level libraries and directly by users. Each part of the code should know
exactly what the instances it uses do, and either use the default one
provided by getInstance for general purpose, being sure nobody with
change its settings under the hood or use a specific instance with
custom settings.

What do you think about it ?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message