Create a new category called HW#2 and place the new object class
called Triple in that category. The Triple class should have base class
Point. Add the instance variable z to your new class and methods z and
z: . Also add instance
method "setX: setY: setZ:" and class method "x: y: z:". You will
need to implement printOn: and storeOn: in the
class so the object can display itself properly. Implement
a way so that Points can be converted to Triples via the @ method but
Triples should then undefine the @ method. Implement
the methods for operator + and -. + and - needs to work for Triple +
Triple, Triple + Point, and Triple + Number. You do not have to
implement the other direction (i.e. Number + Triple) but it is pretty
easy. Do min:, max:, and rounded so they
perform similar tasks that you can SEE in the Point class. Add the
conversions asTriple so it is understood by the Number class, Point
class, and Triple
class. Add asPoint to the Triple class isnce this will help in your
implementation (hint + and -). Note: reuse code of the parent
classes. The
storeOn: method writes out the instance in a format that can then be
read back in and regenerate the object with its state. The storeOn:
method is used by the system and you will find it hard to test, that
is okay.
A check list of all the methods you have added:
Number class - asTriple
Point class - @, asTriple
Triple class - class method x: y: z:, setX: setY: setZ:, printOn:,
storeOn:, z, z:, min:, max:, rounded, @, asPoint, asTriple, +, -
One final important note. You can see how inheritance works since
printOn:, min:, @, and other methods will work even if you don't do
them in the Triple class but they don't return the desired result.
Adam Jonathan Griff,
computer@griffmonster.com
Copyright © University of Colorado. All rights reserved.
Revised: September 11, 1998