the method that the class method uses to create the object is the factory method1. Non-reference factory methodcreate an object and give the property a default value.
// no reference factory method implementation + (student*) student{ return [[Student alloc]init];}
2. Factory Method2.1. To rely on a parameter initialization method-(ID) initwithage: (int) age;2.2. Create an object and give the property a specified value
// The factory method implementation + (student*) Studentwithage: (int) Age Andsex: (char) Sex andsalary: (double ) salary{ return [[Student alloc]initwithage:age andsex:sex andsalary:salary];}
Specification: The method name of the factory method must begin with the class name, note that the prefix is removed, the first letter to the lowercase factory method, not only the use of custom classes, the official class also adhere to this specification
class Student.h
Objective-c Factory method