Re: cast to sub-class or extending instance of super or a.n.other



On Sun, 12 Apr 2009 09:10:45 +0800, "Richard Maher"
<maher_rj@xxxxxxxxxxxxxxxxxx> wrote, quoted or indirectly quoted
someone who said :

What's the best way of "new O = instance of A + stuff.

You need what is called a copy constructor. e.g.

new Dalmatian( dog );

Unfortunately, Java has no easy way of composing one. You must
manually copy field by field in the constructor -- code that will stop
working if Dog acquires any more fields. I proposed Java invent copy
constructors, a bit like COBOL MOVE CORRESPONDING, but everyone shot
me down.

A new Dog ( dog ) takes a Dalmatian and strips it down. You do this
only to save space. A Dalmatian object will do anything a Dog object
does.

If you check out the code for the Replicator you will see constructors
that go back and forth from MiniZip to BigZip etc. BigZip is just a
MiniZip with extra fields.

see http://mindprod.com/products1.html#REPLICATOR

--
Roedy Green Canadian Mind Products
http://mindprod.com

"The most significant trend in the US industry has been the decline in the amount
of energy recovered compared to energy expended. In 1916, the ratio was about 28
to 1, a very handsome energy return. By 1985, the ratio had dropped to 2 to 1,
and it is still dropping."
~ Walter Youngquist, Professor of Geology

By 2003, it had dropped to 0.5 to 1 in the US, making oil extraction no longer economically viable, no matter how high the price of crude.
.



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: 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)
  • 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. ... working if Dog acquires any more fields. ... A new Dog takes a Dalmatian and strips it down. ... that go back and forth from MiniZip to BigZip etc. BigZip is just a ...
    (comp.lang.java.programmer)
  • Re: Static method problems
    ... Dog belong to?", ... That is I consider myself, I'm more of a Java programmer, than an OO programmer. ... A static method ties you, by definition, to a concrete implementation: ...
    (comp.lang.java.programmer)