Objective-C factory method, objective-c Factory

Source: Internet
Author: User

Objective-C factory method, objective-c Factory
The method used to create an object is factory method 1. The no-parameter factory method creates an object and gives the property a default value.

 
// Implementation of the factory method without parameters + (Student *) student {return [Student alloc] init];}
2. Factory method 2. 1. dependent on the initialization method with parameters-(id) initWithAge :( int) age; 2. Create an object and give the attribute a specified value 
// Implementation of the factory method with parameters + (Student *) studentWithAge :( int) age andSex :( char) sex andSalary :( double) salary {return [[Student alloc] initWithAge: age andSex: sex andSalary: salary];}
 
Standard: The method name of the factory method must start with the class name. Note that the prefix should be removed. The first letter must be the lower-case factory method. Not only do custom classes are used, but official classes also comply with this standard.

Class Student. h

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.