Obective-C, the language with a death sentence...
Interface declaration
Defined in a header file (with a .h extension)
brush: objc
@interface: Animal : NSObject {
// Protected instance variables (not recommended)
}
@property (copy) NSString *name;
-(NSString*) getName; // object method
-(id)initWithName:(NSString*)name; // Initializer
+(int) getPopulation; // class method
+(void)initialize; // class initializer
@end
Implementation
Defined in a module file (with a .m extension)
brush: objc
static int population;
@implementation Animal {
// Private instance variables
NSString _name;
}
-(id)initWithName:(NSString*) name {
self = [super init]; // Always call the base class initializer
if (self) {
// Custom setup goes here
_name = name;
}
}
+(int) getPopulation {
return population;
}
+(void)initialize {
if (self == [Animal class]) {
// Make sure this is only executed once
}
}
@end