home *** CD-ROM | disk | FTP | other *** search
- /* Objective_C Implementation of the Fruit Class: Fruit.m */
-
- #import "Fruit.h"
-
- @implementation Fruit : Object
-
- /* Initialize a new fruit. */
- -init
- {
- [super init]; // do Object's init. Now my own:
- [self setDiameter:1]; // init the diameter
- [self setColor:"green"]; // init the color
- return self; // return the new instance
- }
-
- /* Set the color of the fruit. */
- -setColor:(char*)aColor
- {
- color = aColor;
- return self;
- }
-
- /* Return the fruit's color. */
- - (char*)color
- {
- return color;
- }
-
- /* Set the fruit's diameter. */
- -setDiameter: (int) aSize
- {
- diameter = aSize;
- return self;
- }
-
- /* Return the fruit's diameter. */
- - (int) diameter
- {
- return diameter;
- }
-
- /* Tell the fruit to increase its diameter. */
- - grow
- {
- [self setDiameter:([self diameter] + 1)];
- return self;
- }
-
- @end
-