OC language--recombination and inheritance

Source: Internet
Author: User

1. Composite

1.0 Compounding and inheritance

-"describes the relationship between a class and a class or object and an object in two ways: 1. Inheritance 2. Compound;

-"Inheritance can define a new class with all the functions of the parent class.

-"composite, the object can refer to other objects.

Difference:

-"Compound: has-a Car has a tire (inclusive relationship)

-"Inherited: Is-a A Male is a person (affiliation)

1. 1 Basic syntax examples for compositing

#import "Tire.h" #import "Engine.h" @interface car:nsobject{    //Save the address of the tyre and engine    *_engine;    Tire *_tires[4];} -(Car *) init;-(void) run;-(void) Setengine: (Engine *) newengine;-(engine *) engine; @end

2. Use of @class keywords

2. 1 Basic concepts and basic grammar

-"@class The role of the keyword: declaring a pre-reference to a class

-"Grammar writing: @class class name;

Note: When class A needs to use the class name of Class B,

We can use @class to declare this class B;

Use @class B in the A.h file of Class A;

In the a.m., use #import "B.h" to import the header file of Class B.

2. The difference between the 2 @class and the #import

    1. @class is merely a declaration of a single class, equivalent to an extern statement;
    2. #import is to import the entire header file, equivalent to # include

OC language--recombination and inheritance

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.