我试图学习客观和有问题。 我创立了班级创作,并将班级扩大。
但是,当采用所谓的方法时,回返结果就象从名状阶级而不是Dog中来。
Link for github 。
p.s. 如果发现her子和记忆泄露点,请向我报告。
法典:
@interface Creature: NSObject
- (NSString *)state;
..
@implementation Creature
- (NSString *)state
{
return [_name stringByAppendingString: ([self isHungry] ? @" is hungry" : @" not hungry")];
}
// Dog
@interface Dog: Creature
..
@implementation Dog
- (NSString *)state
{
return [[super state] stringByAppendingString: ([self isFriendly] ? @" and friendly" : @" and unfriendly")];
}
And calling method
Dog *creature = [Dog CreatureBorn];
NSLog([creature state]);