I have experience with object-oriented programming however this situation is unfamiliar for some reason. Consider the following Objective-c 2.0 code:
@interface A : NSObject
@end
@implementation A
- (void) f {
[self g];
}
@end
@interface B : A
@end
@implementation B
- (void) g {
NSLog(@"called g...");
}
@end
Is this the correct way to call a method on a child class from a method in the parent class? What happens if another child class doesn’t implement method g? Perhaps there’s a better way to solve this like an abstract method in the parent class A?
The key is to have a method in the parent class that may be overriden in the child class.
You see, your child class will override the parent method with its own implementation. You might see it used like this:
Output:
Yipe! Yipe! Yipe!