[Edu-sig] How to Think Like A Computer Scientist

kirby urner kirby.urner at gmail.com
Tue Mar 28 15:41:00 CEST 2006


Are you sure?

  public static Complex add (Complex a, Complex b) {
    return new Complex (a.real + b.real, a.imag + b.imag);
  }

To invoke this method, we would pass both operands as arguments:
    Complex sum = add (x, y);

Written as an object method, it would take only one argument, which it
would add to the current object:

  public Complex add (Complex b) {
    return new Complex (real + b.real, imag + b.imag);
  }

Looks immutable to me, i.e. we're not changing in place but returning
a new complex.  I guess you're referring to the fact that real and
imag aren't private e.g.:

    Complex x = new Complex ();
    x.real = 1.0;
    x.imag = 2.0;
    Complex y = new Complex (3.0, 4.0);

Yes, that's a change-in-place ability, true.

Kirby


On 3/28/06, Arthur <ajsiegel at optonline.net> wrote:
>
> Ironically, apropos of the recent discussion
>
> How to Think Like A Computer Scientist - Java Version
> introduces the fundamental concepts of Object Oriented Programming by way of
> the creation of a mutable complex number.
>
> http://www.ibiblio.org/obp/thinkCSjav/chap13.htm
>
> FWIW.
>
> Art
>
>
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>


More information about the Edu-sig mailing list