OBJECTIVE-C Classes and objects

Source: Internet
Author: User

Object oriented

Object-oriented (object-oriented) is based on process-oriented (procedure-oriented)

Object-oriented Emphasis object < conductor > OC, Java language is object-oriented

Process oriented < performer > C language is process oriented

Object-oriented is a programming idea to construct test reconstruction software by using the concepts of object class encapsulation and inheritance polymorphism and message.

Object-oriented features a: Package B: Inherit C: polymorphic

The characteristics of object-oriented thought a: It is a thought that is more in line with people's thought habits B: It simplifies complex content C: It makes us from the executor to the conductor

The advantages of object-oriented are consistent with the way people think from analysis to design to coding. Consistent model representation with high continuity software reusability

Classes and objects

Class description of things in the real world (member variables and methods)

Objects in the real world actually exist specific individuals

Example code One

#import<Foundation/Foundation.h>/** Declaration of Class **/@interfaceCar:nsobject {//The declaration of member variables within curly braces is initialized to 0 by default (not the same as the curly braces of the function); NSObject: Root class gives car the ability to create objects    @public//This keyword allows member variables to be accessed by the outside world    intAge//member Variable 1    intHeight//member Variable 2}- (void) run;//Object Methods@end/** Implementation of class **/@implementationCar- (void) Run {NSLog (@"Car%i years old,%ICM, it's running", age,height);}@end/** Main function **/intMain () {Car*c = [CarNew];//Creating ObjectsC->age =Ten;//set the properties of an objectC->height = the;//set the properties of an object[C Run];//Calling Object Methods    return 0;}/** Memory Analysis **///[Car New] Creates a new object each time and returns the address value of the object so you should save the object's address with a pointer variable

Example code two

#import<Foundation/Foundation.h>@interfacePerson:nsobject {@public    intAge ; intheight;}- (int) Test: (intI//declaration with a parameter method//-(int) test: (int) i test1: (int) i1;//Declaration of a multi-parameter method@end@implementation Person- (int) Test: (intI//implementation of the method with parameters    returnIi;}//-(int) test: (int) i test1: (int) I1 {//implementation of multi-parameter method//return i * I1;//}@endintMain () { person*p = [PersonNew]; intTMP = [P test:7];//call with a parameter method//int i = [P test:10 test1:9];//invocation of a multi-parameter methodNSLog (@"the value of the test method is:%i", TMP); return 0;}/** Note **///two object methods with the same name are not allowed in the same class/** Method Syntax detailed **///-(int) test: (int) i;//Method Type (method return value type) method Name: (parameter type) parameter name;//[P Test:7]//[pointer variable name Method name: actual parameter]//-(int) test: (int) i test1: (int) i1;//Method Type (method return value type) method Name: (parameter type) parameter name Method name: (parameter type) parameter name;//[P test:10 Test1:9]//[pointer variable name Method name: Actual parameter method name: actual parameter]

OBJECTIVE-C Classes and objects

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.