From: Nina J. <ni...@ac...> - 2009-04-12 12:34:43
|
Hi All, Just few thoughts, in support to Stefan suggestions: A possible solution toward more consistent design (though requiring some API changes) would be to make use of generics, by defining base class e.g. IChemObjectSet<T extends IAtomContainer> with methods add(T) instead of addAtomContainer(), iterator<T> instead of iterator<IAtomContainer> ,Iterable<T> etc. and then IAtomContainerSer extends IChemObjectSet<IAtomContainer> and IMoleculeSet extends IChemObjectSet<IMolecule> which will naturally follow to iterable<IAtomcontainer> and iterable<IMolecule> Best regards, Nina Stefan Kuhn wrote: > Hi all, > I fixed today the problem with JCP throwing ClassCastExceptions when saving. > The background was that the ControllerHub actually added IAtomContainers to > the MoleculeSet in the ChemModel. This is possible since the IMolecule set, > apart from addMolecule(IMolecule) etc., also has > addAtomContainer(IAtomContainer) etc. from the IAtomContainer it extends. > Then there is the method Iterable<IAtomContainer> molecules() which returns > IAtomContainers since it uses atomContainers() in the superclass. > I think this is inconsistent design and is prone to cause trouble for other > people as well. I am not quite sure what to do best, I must admit. The only > idea I have right now is to overwrite the addAtomContainer etc. methods in > MoleculeSet and have them throw an exception. The molecules() method would > then be guaranteed to return IMolecules, but it might still be good to change > its return type to IMolecule and do the cast in there. > Stefan > |