Recommendations for Externalizable, new type ExternalizedImmutable

Are there any technical reasons why the Externalizable interface isn't as powerful as Serializable? For instance, providing 3 public methods, default zero-arg constructor, readExternal, writeExternal is quite painful when trying to design objects that are immutable, serialized, and maximally efficient.

The other thing about Externalizable is the fact that I cannot tag any fields as final to strongly enforce the immutable contract.

So my question is this. Why can the serialize code for Serializable tagged objects deal with final (aka const) objects and be able to operate on private or protected methods such as readResolve yet Externalizable is not afforded the same flexibility? I think that native Java deserializing of externalized objects can skirt the access/const rules/contracts that Java stipulates, because Serializable can operate on immutable types - so why not give Externalizable objects that same power?

I guess the answer to that is it is too late to make a breaking change to the Externalizable contract. So I would like to propose a third alternative serializing type (suggest ExternalizedImmutable) with the interface of Externalizable and the wielding power of Serializable.

Yes I know I can use Serializable to get around Externalizable's problems but we have designed a massive OODB which saves immutable state changes. We have done tests that show that we can halve our backend persistent store if we implement serialized objects with the Externalizable interface.

Thanks for any responses,

Ryan

[1571 byte] By [RyanFa] at [2007-11-27 0:29:38]
# 1

On further reflection I have realized the flaws in the proposal for an ExternalizedImmutable, I can't think of any reasonable way Externalized objects could deal with const/final data.

Saying that, I think it is still possible to create an Externalized object type whose extra Externalized tidbits (default constructor, write and readExternal), could be private or protected. That way a class can guarantee immutability (well, ignoring the other issues such as being passed references to mutable types...). Additionally, the interface would be a wee-bit more cleanly and satisfying.

<edit>

In FACT! Now that I think about it, the Externalizable interface could be made to do this without breaking existing code. Since access permissions can be made to be more permissive the interface could be coded to be more restrictive!

</edit>

Any thoughts?

Regards,

Ryan

Message was edited by:

RyanF

RyanFa at 2007-7-11 22:32:13 > top of Java-index,Core,Core APIs...