Objc01
- 74. クラス定義とヘッダファイル
#import <Foundation/NSobject.h>
@interface Alpha : NSObject
{
…
}
- (void)doSomething;
@end
#import Alpha.h
@interface Beta : Alpha
{
…
}
…
@end
#import Beta.h
@interface Gammma : Beta
{
…
}
…
@end
#import Alpha.h
…
@implementation Alpha
…
- (void)doSomething { … }
…
@end
#import Beta.h
…
@implementation Beta
…
@end
#import Gamma.h
…
@implementation Gamma
…
[self doSomething];
…
@end
Alpha.h
Beta.h
Gamma.h
Alpha.m
Beta.m
Gamma.m
- 75. クラス定義とヘッダファイル
#import <Foundation/NSobject.h>
@interface Alpha : NSObject
{
…
}
- (void)doSomething;
@end
#import Alpha.h
@interface Beta : Alpha
{
…
}
…
@end
#import Beta.h
@interface Gammma : Beta
{
…
}
…
@end
#import Alpha.h
…
@implementation Alpha
…
- (void)doSomething { … }
…
@end
#import Beta.h
…
@implementation Beta
…
@end
#import Gamma.h
…
@implementation Gamma
…
[self
doSomething];
…
@end
Alpha.h
Beta.h
Gamma.h
Alpha.m
Beta.m
Gamma.m
図のGamma.mではメソッド定義内で
doSomethingというメソッドを呼びだし
ている
これはクラスAlphaから継承された
もの
- 76. クラス定義とヘッダファイル
#import <Foundation/NSobject.h>
@interface Alpha : NSObject
{
…
}
- (void)doSomething;
@end
#import Alpha.h
@interface Beta : Alpha
{
…
}
…
@end
#import Beta.h
@interface Gammma : Beta
{
…
}
…
@end
#import Alpha.h
…
@implementation Alpha
…
- (void)doSomething { … }
…
@end
#import Beta.h
…
@implementation Beta
…
@end
#import Gamma.h
…
@implementation Gamma
…
[self
doSomething];
…
@end
Alpha.h
Beta.h
Gamma.h
Alpha.m
Beta.m
Gamma.m
Gamma.mがインポートしている
Gamma.hはBeta.hをインポートしている
Beta.hはAlpha.hをインポートしている為
メソッドdoSomethingの宣言を
参照できる
- 77. クラス定義とヘッダファイル
#import <Foundation/NSobject.h>
@interface Alpha : NSObject
{
…
}
- (void)doSomething;
@end
#import Alpha.h
@interface Beta : Alpha
{
…
}
…
@end
#import Beta.h
@interface Gammma : Beta
{
…
}
…
@end
#import Alpha.h
…
@implementation Alpha
…
- (void)doSomething { … }
…
@end
#import Beta.h
…
@implementation Beta
…
@end
#import Gamma.h
…
@implementation Gamma
…
[self
doSomething];
…
@end
Alpha.h
Beta.h
Gamma.h
Alpha.m
Beta.m
Gamma.m
クラス定義ではいくらでも継承関係を繰
り返す事が出来る
しかし,このインポート方法を守ってい
る限りクラス階層の下位のどのクラス
定義からも,上位クラスのインタフェー
スが見える事になる