From: Artur H. <wis...@wp...> - 2002-11-25 11:43:04
|
> On Monday 25 November 2002 10:17 am, Artur Hefczyc wrote: > > 1. Maybe it would be useful to set requirements for modules to > > implement Serializable and Cloneable interfaces? > Should all classes impliment Clonable? > What should be written about Serializable? I am not sure if this is necessary or useful, it is just suggestion. And I am not going to suggest implement Cloneable in ALL classes. Usually modules consists of many classes but we access them only through one class or one interface. So this one class/interface would implement required interface. See comments below: 1. Cloneable: I am not sure, it depends on module destination. But it is common to set policy for all modules to be Cloneable if we access them only by Interfaces. If for some reason we want another instance of some object but a little modified it is easier to create copy of first object and modify it. But create exact copy of class instance if we only access it by Interface can be difficult or even impossible. We can, of course, call Factory method for new instance of our class and rebuild first object, but it can be unefficient. The solution is to add implementation of Cloneable interface. The example of such case may be when we have some Image object created partialy from downloaded data and partialy from calculated data. We want another Image but rotated a little. So create new Instance of such object is really time expensive and difficult. So if Image implements Cloneable it is easy to get new copy rotate it and have both Images for presentation. 2. Serializable: Necessary only if geotools wants to save objects to disk file or send them through network interfaces. I am not sure if it is planed or useful. However JavaBeans architecture supports saving beans to file in XML format. There is built-in engine in JDK to accomplish this. The most common use of this is to save all modules settings to some config file and restore them during next application start. regards Artur Hefczyc -- Artur Hefczyc art...@pl... Open Source Developer http://wttools.sourceforge.net/ |