//// eocperson.h// OC High Efficiency 52: Refer to other header files as few as possible in the header file of the class//// created by zoujie on 15/10/8.// COPYRIGHT&NBSP;?&NBSP;2015 year zoujie. all rights reserved.//#import <foundation/ foundation.h>//#import "EOCEmployer.h" @class eocemployer;//forward to declare the class, the time to introduce the header file as far as possible, only to determine the need to introduce If the EOCEmployer.h is introduced into EOCPerson.h, all the contents of EOCEmployer.h will be introduced as soon as the EOCPerson.h is introduced. The forward declaration also solves the problem of two classes referencing each other @interface eocperson : nsobject@property (nonatomic,copy) NSString *firstName; @property (nonatomic,copy) NSString *lastName; #pragma mark -essentials/* * do not introduce a header file unless it is necessary. In general, you should use forward declarations in the header file of a class to refer to other classes and to introduce which classes of header files in the implementation file. Doing so minimizes the coupling between classes. * sometimes cannot use forward declarations, such as declaring a class to follow a protocol. In this case, try to move the "this class follows an agreement" declaration to "Class-continuation classification". If not, put the protocol in a single header file and introduce it. */@property (nonatomic,strong) EOCEmployer *employer; @end
eocperson.m//oc High Efficiency 52: As few as possible in the header file of the class refer to other header files////Created by Zoujie on 15/10/8.//Copyright? 2015 Zoujie. All rights reserved.//#import "EOCPerson.h" #import "EOCEmployer.h" @implementation eocperson@end
eocemployer.h//oc High Efficiency 52: As few as possible in the header file of the class refer to other header files////Created by Zoujie on 15/10/8.//Copyright? 2015 Zoujie. All rights reserved.//#import <Foundation/Foundation.h> @class eocperson @interface eocemployer:nsobject-(void ) AddEmployee: (Eocperson *) person;-(void) Deleteemployee: (Eocperson *) person; @end
eocemployer.m//oc High Efficiency 52: As few as possible in the header file of the class refer to other header files////Created by Zoujie on 15/10/8.//Copyright? 2015 Zoujie. All rights reserved.//#import "EOCEmployer.h" #import "EOCPerson.h" @implementation eocemployer@end
OC High Efficiency 52: (ii) in the header file of the class as few as possible to refer to other header files