发表于: 2016-12-11 12:22:26

2 845


今天完成的事情: 复习完第五章复合。
明天计划的事情:今天还会继续往后看可能到第八章了明天。
遇到的问题: - (id) init{}类接口中并未声明,为何实现了? 还有description也未在接口声明但是也实现了,书上说的我不理解。
收获:存取方法更加熟练。对何时使用继承何时使用复合也有一点心得了。模仿了一个小程序。

#import <Foundation/Foundation.h>


@interface Time : NSObject

@end


@implementation Time


- (NSString *) description

{

    return (@"需要三个月.");

}//time


@end


@interface Process : NSObject

@end


@implementation Process


- (NSString *) description

{

    return (@"每天除了吃饭睡觉剩下时间全部用来学习敲代码,还有师兄指点交流。");

} //process


@end


@interface Become : NSObject

@end


@implementation Become


- (NSString *) description

{

    return (@"你会迅速成为一名有信仰的IOS软件研发工程师!");

} //become


@end



@interface Completexiuzhen : NSObject

{

    Time *time;

    Process *process;

    Become *become;

}


- (Time *) time;

- (void) setTime: (Time*) newTime;

- (Process *) process;

- (void) setProcess: (Process *) newProcess;

- (Become *) become;

- (void) setBecome: (Become *) newBecome;

- (void) print;


@end


@implementation Completexiuzhen


- (Time *) time

{

    return (time);

}//time


- (void) setTime: (Time *) newTime

{

    time = newTime;

}//setTime


- (Process *) process

{

    return (process);

} //process


- (void) setProcess: (Process *) newProcess

{

    process = newProcess;

}//setProcess


- (Become *) become

{

    return (become);

}//become


- (void) setBecome: (Become *) newBecome

{

    become = newBecome;

}//setBecome


- (void) print

{

    NSLog (@"%@", time);

    NSLog (@"%@", process);

    NSLog (@"%@", become);

}//print


@end//Completexiuzhen



int main (int argc, const char * argv[])

{

    Completexiuzhen *xiuzhen = [[Completexiuzhen alloc] init];

    Time *time = [[Time alloc] init];

    [xiuzhen setTime: time];

    Process *proc = [[Process alloc] init];

    [xiuzhen setProcess: proc];

    Become *bec = [[Become alloc] init];

    [xiuzhen setBecome: bec];

    [xiuzhen print];

    

    return (0);

}

把上面这些代码分别拆分到各自文件,并且理解了@class的用法。


返回列表 返回列表
评论

    分享到