More clarity in the invocation process
+ For static methods
1 //class definition2 @interfacepeople:nsobject{3 int_age;4nsstring*_name;5 }6 //Factory method Static7+ (people*) Peoplewithage: (int) Age Andname: (nsstring*) name;8 9-(ID) Initwithage: (int) Age Andname: (nsstring*) name;Ten-(int) Getage; One-(nsstring*) GetName; A @end - - the //class Implementation - @implementationpeople - - //Factory Method ++ (people*) Peoplewithage: (int) Age Andname: (nsstring*) name{ - return[[People alloc] initwithage:age Andname:name]; + } A at //Initialize Method --(Instancetype) Initwithage: (int) Age Andname: (NSString *) name{ -self = [super init];//executing the Parent class Init method - if(self) { -_age =Age ; -_name =name; in } - returnSelf ; to } + --(int) getage{ the return_age; * } $ Panax Notoginseng-(nsstring*) getname{ - return_name; the } + @end A the + //called - intMainintargcChar*argv[]) { $People *p = [People peoplewithage:TenAndname:@"Jinpangpang"]; $NSLog (@"p.age%d, p.name%@", [P getage],[p getName]); - - @autoreleasepool { the returnUiapplicationmain (argc, argv, Nil, nsstringfromclass ([appdelegateclass])); - }Wuyi}
Objective-c Factory method