面向对象编程入门
1. 传统编程的局限
在传统的编程中,我们可能会编写类似下面的代码来绘制不同的形状:
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 32 80 50) in red
超级会员免费看
订阅专栏 解锁全文
1463

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



