面向对象编程增加间接层对程序的扩展

一下通过代码做出解释:

View Code
 1 #import <Foundation/Foundation.h>
 2 int main(int argc, const char * argv[])
 3 {
 4     @autoreleasepool
 5     {
 6         NSLog(@"The numbers forme 1 to 5");
 7         for(int i = 1; i <= 5; i++)
 8         {
 9              NSLog(@"%d\n", i);
10         }
11     }
12     return 0;
13 }
View Code
 1 #import <Foundation/Foundation.h>
 2 int main(int argc, const char * argv[])
 3 {
 4     @autoreleasepool
 5     {
 6         int count = 5;
 7         NSLog(@"The numbers forme 1 to %d", count);
 8         for(int i = 1; i <= count; i++)
 9         {
10              NSLog(@"%d\n", i);
11         }
12     }
13     return 0;
14 }
View Code
 1 #import <Foundation/Foundation.h>
 2 int main(int argc, const char * argv[])
 3 {
 4     @autoreleasepool
 5     {
 6         int fist = 1, count = 5;
 7         NSLog(@"The numbers forme %d to %d", fist, count);
 8         for(int i = fist; i <= count; i++)
 9         {
10              NSLog(@"%d\n", i);
11         }
12     }
13     return 0;
14 }
View Code
 1 #import <Foundation/Foundation.h>
 2 int main(int argc, const char * argv[])
 3 {
 4     @autoreleasepool
 5     {
 6         int fist, count;
 7         scanf("%d %d", &fist, &count);
 8         NSLog(@"The numbers forme %d to %d", fist, count);
 9         for(int i = fist; i <= count; i++)
10         {
11              NSLog(@"%d\n", i);
12         }
13     }
14     return 0;
15 }

请观察以上代码,发现是怎么一步一步的对程序扩展的,相信你就的增加一个间接层就有所了解了。

原文地址:https://www.cnblogs.com/chenxiangxi/p/2456883.html