Demoting and Promoting Serialised Objects



I see a general problem I call demoting and promoting objects.

A Dog gets promoted to a Dalmatian object by gaining extra
Dalmatian-specific fields.

A Dalmatian gets demoted to Dog object by stripping off its Dalmatian
specific fields.

The object itself is unchanged. You create a new modified object and
discard the old one.


Why would you do such a thing?

1. to strip and object down for export, serialisation, or RMI
transport.

2. to strip an object of confidential information before handing in
on.

3. to avoid having to give confidential code used to process, edit or
construct your objects when all they will do is view them.

The way you did the equivalent thing in COBOL was a MOVE CORRESPONDING
that copied field by field. In Java traditionally you do the same
thing writing code guaranteed to stop working the instant any of the
class structure changes.

How might you handle this more elegantly?

1. a class parser then generates code to do the move-corresponding.

2. Java gain some feature to easily create copy constructor so you
could say:

something like:

/**
* cloning constructor
* Makes a Dog out of any Dog object including a Dalmatian object.
* The new object will have only the Dog fields and methods, even if
* cast back to the original type.
*/
Dog ( Dog ) { Magic.copy(); }

Where copy is some magic JNI or new Java feature.

The assembler code theoretically could be just a block byte move of
dog's object size bytes -- extremely fast compared with field by field
copy.
..



--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
.



Relevant Pages

  • Re: Demoting and Promoting Serialised Objects
    ... >I see a general problem I call demoting and promoting objects. ... > A Dalmatian gets demoted to Dog object by stripping off its Dalmatian ... Java gain some feature to easily create copy constructor so you ...
    (comp.lang.java.programmer)
  • Re: cast to sub-class or extending instance of super or a.n.other
    ... You need what is called a copy constructor. ... Java has no easy way of composing one. ... working if Dog acquires any more fields. ... A new Dog takes a Dalmatian and strips it down. ...
    (comp.lang.java.programmer)
  • Re: Please help - dog with kidney failure
    ... Our dalmatian hasn't been eating for the last ... > thought she had blood in her urine - we would see blood on the fur. ... > her back for more fluids tomorrow. ... Change dog breeds: quit buying dalamations. ...
    (rec.pets.dogs.health)
  • Re: About the private member
    ... You might use code like your example in a copy constructor ... Dalmatian to Dog. ... Roedy Green Canadian Mind Products ...
    (comp.lang.java.programmer)
  • Re: charming, again
    ... A Dalmatian broke sits.. ... I imagine the owner proofed that dog VERY well, but even then, this HAD to be a worse case scenario, and the sit held. ... Of all the dogs in there, the last one I would have attacked, were I a sentient dog, would have been the Airedale. ... How was the Dalmatian removed? ...
    (rec.pets.dogs.behavior)