面向对象编程入门与Objective - C实现
传统编程的局限
在传统的编程方式中,我们以一个绘制图形的程序为例。以下是一段代码:
shapes[0].fillColor = kRedColor;
shapes[0].bounds = rect0;
ShapeRect rect1 = { 30, 40, 50, 60 };
shapes[1].type = kRectangle;
shapes[1].fillColor = kGreenColor;
shapes[1].bounds = rect1;
ShapeRect rect2 = { 15, 18, 37, 29 };
shapes[2].type = kEgg;
shapes[2].fillColor = kBlueColor;
shapes[2].bounds = rect2;
ShapeRect rect3 = { 47, 32, 80, 50 };
shapes[3].type = kTriangle;
shapes[3].fillColor = kRedColor;
shapes[3].bounds = rect3;
drawShapes (shapes, 4);
return (0);
这个程序运行时会输出:
drawing a circle at (0 0 10 30) in red
drawing a rectangle at (30 40 50 60) in green
drawing an egg at (15 18 37 29) in blue
drawing a triangle at (47 3
超级会员免费看
订阅专栏 解锁全文
4

被折叠的 条评论
为什么被折叠?



