Talk:BioJava3 Design
From BioJava
I would prefer
"Use immutable classes wherever possible."
to
"Use of JavaBeans concepts wherever possible, e.g. getters/setters. This would enhance Java EE compliance and improve integration into larger things. DON'T do this where immutability is key to efficiency though, like with Strings."
To me "JavaBeans concepts" includes PropertyChangeListener and VetoablePropertyChangeListener support, and I am not convinced that these are good things to have in low-level libraries.
Most dependency injection libraries (Guice, PicoContainer/NanoContainer, Spring) are happy using constructor injection instead of field or method injection.
See e.g.
http://code.google.com/p/google-guice/wiki/GuiceBestPractices
http://www.picocontainer.org/constructor-injection.html
--Heuermh
An alternative view would be the EJB3 view where all entities have parameterless constructors and getters/ setters. From memory a fair bit of saftey can be built in by making the setters package private or protected. Another level of 'safety' is to go for interface based design and access. For any given entity you have an interface that exposes only the necessary setters. If the programmer is working at the level of the interface then they don't see the setters. If they want to introspect or cast the class then they will see them but if they are doing this then you have to expect they know the dangers of doing this. An even simpler approach is to javadoc setters appropriately pointing out how inconsistencies might occur if setters are called without fore-thought.
I think it is time we stop hand holding developers so much. Developers should be smart people. A good developer will realise that playing with setters can cause problems, this is not a great reason for taking them away. One of the most annoying things about biojava is that you have great difficulty in modifying anything such as a Sequence once it has been created. I don't think this is ideal.
The principle that things should be immutable is a bit like the idea that unchecked exceptions are bad. In theory it is true but in practice it rapidly makes code unworkable.
--Mark 03:59, 29 February 2008 (EST)

