面向对象编程增加间接层对程序的扩展
一下通过代码做出解释:
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 }
请观察以上代码,发现是怎么一步一步的对程序扩展的,相信你就的增加一个间接层就有所了解了。
吾屋无污,吴捂屋污,诬吾污屋,吾晤吴污,吾无物污,吴侮污吾,吾忤吴屋,悟吴诬吾,污屋吴污,吴侮吾污,吾勿武侮,吾唔吴误,诬侮污吾,吾屋悟忤.