The quick answer to your question is inheritance (:
) is a universal object oriented programming principle and inclusion (#import
) provides declarations of all symbols used while compiling, which is specific to C like programming languages.
In Objective-C, there is no global symbol space like there is in Java. Each file must include the definition for every symbol used.
This is done by using header files and having interfaces separated from implementations.
The Objective-C compiler only builds .m files, never .h files. The #import
statement copies the contents of the .h file into the .m file at build time.
MyFoo.h
@interface MyFoo : NSObject
@end
MyBar.h
#import "MyFoo.h"
@interface MyBar : MyFoo
@end
MyBar.m
#import "MyBar.h"
@implementation MyBar
@end
At compile time only MyBar.m is compiled. To the compiler the #import
s have their source dumped into MyBar.m.
How the compiler see MyBar.m
@interface MyFoo : NSObject
@end
@interface MyBar : MyFoo
@end
@implementation MyBar
@end
As you can see, the complier cares about the implementation of MyBar and uses the interfaces as a way to provide context for all the declared symbols.