#import <Foundation/Foundation.h>
typedefenum
{
kCircle,
kRectangle,
kOblateSpheroid
}ShapeType;
typedefenum
{
kRedColor,
kGreenColor,
kBlueColor
}ShapeColor;
typedefstruct
{
int x,y,width,height;
}ShapeRect;
typedefstruct
{
ShapeType type;
ShapeColor fillColor;
ShapeRect bounds;
}Shape;
NSString * colorName(ShapeColor colorName )
{
switch(colorName)
{
case kRedColor:
return @"red";
casekGreenColor:
return @"green";
case kBlueColor:
return @"blue";
}
return@"no color";
}
@interface Circle:NSObject
{
ShapeColor fillColor;
ShapeRect bounds;
}
-(void) setFillColor:(ShapeColor) fillColor;
-(void) SetBounds:(ShapeRect) bounds;
-(void) draw;
@end
@implementation Circle
-(void)setFillColor:(ShapeColor) c
{
fillColor = c;
}
-(void) SetBounds:(ShapeRect) b
{
bounds = b;
}
-(void) draw
{
NSLog(@"drawing a circle at (%d %d %d %d) in %@ ",
bounds.x,bounds.y,bounds.width,bounds.height,colorName(fillColor));
}
@end
@interface Rectangel:NSObject
{
ShapeColor fillColor;
ShapeRect bounds;
}
-(void) setFillColor:(ShapeColor) fillColor;
-(void) SetBounds:(ShapeRect) bounds;
-(void) draw;
@end
@implementation Rectangel
-(void)setFillColor:(ShapeColor) c
{
fillColor = c;
}
-(void) SetBounds:(ShapeRect) b
{
bounds = b;
}
-(void) draw
{
NSLog(@"drawing a Rectangle at (%d %d %d %d) in %@ ",
bounds.x,bounds.y,bounds.width,bounds.height,colorName(fillColor));
}
@end
void drawShapes(id shapes[],int count)
{
for( int i = 0; i < count; ++ i )
{
id shape = shapes[i];
[shape draw];
}
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
id shapes[3];
ShapeRect rect0 = {0,0,30,40};
shapes[0] = [Circle new];
[shapes[0] SetBounds:rect0];
[shapes[0] setFillColor:kRedColor];
ShapeRect rect1 = {0,0,30,40};
shapes[1] = [Rectangel new];
[shapes[1] SetBounds:rect1];
[shapes[1] setFillColor:kGreenColor];
drawShapes(shapes, 2);
}
return 0;
}