langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
53
Task/Inheritance-Multiple/Objective-C/inheritance-multiple.m
Normal file
53
Task/Inheritance-Multiple/Objective-C/inheritance-multiple.m
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
@interface Camera : NSObject {
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation Camera
|
||||
@end
|
||||
|
||||
@interface MobilePhone : NSObject {
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation MobilePhone
|
||||
@end
|
||||
|
||||
@interface CameraPhone : NSObject {
|
||||
Camera *camera;
|
||||
MobilePhone *phone;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation CameraPhone
|
||||
|
||||
-(id)init {
|
||||
if ((self = [super init])) {
|
||||
camera = [[Camera alloc] init];
|
||||
phone = [[MobilePhone alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[camera release];
|
||||
[phone release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(void)forwardInvocation:(NSInvocation *)anInvocation {
|
||||
SEL aSelector = [anInvocation selector];
|
||||
if ([camera respondsToSelector:aSelector])
|
||||
[anInvocation invokeWithTarget:camera];
|
||||
else if ([phone respondsToSelector:aSelector])
|
||||
[anInvocation invokeWithTarget:phone];
|
||||
else
|
||||
[self doesNotRecognizeSelector:aSelector];
|
||||
}
|
||||
|
||||
-(BOOL)respondsToSelector:(SEL)aSelector {
|
||||
return [camera respondsToSelector:aSelector]
|
||||
|| [phone respondsToSelector:aSelector]
|
||||
|| [super respondsToSelector:aSelector];
|
||||
}
|
||||
|
||||
@end
|
||||
Loading…
Add table
Add a link
Reference in a new issue