home *** CD-ROM | disk | FTP | other *** search
- /* Objective_C Implementation of the Fruit Class */
-
- #import "Fruit.h"
-
- @implementation Fruit : Object
- {
- char * color;
- int diameter;
- }
-
- // Create a new fruit by using the superclass 'new' method
- + create {
- id newInstance; // local variable declaration
-
- newInstance = [ self new ];// create new instance
- [ newInstance diameter: 1];// set the diameter
- [ newInstance color: "green" ]; // set the color
- return newInstance; // return the new instance
- }
-
- // Set the color instance variable fo the Fruit Object
- -color: (char*) aColor{
- color = aColor;
- return self;
- }
-
- //Return the value of the color instance variable
- - (char*) color {
- return color;
- }
-
- //Set the diameter instance variable of the Fruit objects
- -diameter: (int) aSize {
- diameter = aSize;
- return self;
- }
-
- //Return the value of the diameter instance variable
- - (int) diameter {
- return diameter;
- }
-
- // Tell a Fruit object to increase its diameter
- - grow {
- diameter = diameter + 1;
- return self;
- }
-
- @end
-