12: Object-oriented inheritance of three major features (encapsulation, inheritance, polymorphism)

Source: Internet
Author: User

This section of the Knowledge Points:
    1. Inherit Basic concepts
    2. The inheritance relationship in OC
    3. How to implement inheritance in OC
1. Basic concepts of inheritance
    • The inheritance in real life

    • A vehicle class is a base class (also known as a parent class), which typically features common to all modes of transport, such as speed and number of rated manned

    • According to our routine, we will continue to classify vehicles, we think of cars and airplanes, and so on, cars and airplanes are also equipped with the speed and rated number of manned, which is common to all modes of transport, so that the car or aircraft class can inherit the transport class, So when we build cars and airplanes, we don't have to define the members and methods that we already have in the transport class (the base class), and we just need them. Specific characteristics of automotive and aircraft classes.

    • The characteristics of aircraft and automobiles are increased by the original characteristics of the vehicle class, so the aircraft class and the automobile class are derived classes (also called sub-categories) of the vehicle class. And so on, layers increment, the concept that the seed class obtains the parent class attribute is to inherit

    • The importance of inheritance
Inheritance relationships in 2.OC

    • Class B Inherits Class A, then Class B will have all the properties and methods of Class A, when we say Class A is the parent class of Class B, and Class B is a subclass of Class A.

    • Class C Inherits Class B, then the Class C will have all the properties and methods in Class B, including the Class B inherits from Class A properties and methods, at this point we say that Class B is the parent class of Class C, Class C is a subclass of Class B

    • Attention:

      • The private property of the base class is inherited and cannot be accessed in subclasses.
      • Inheritance in OC is Single inheritance: That is, a class can only have one parent class and cannot inherit multiple parent classes
      • The relationship between the subclass and the parent class is also known as the ISA (is a) relationship, we say that the subclass Isa parent class, that is, the subclass is a parent class, such as the dog class inherits the animal class, then we say the dog Isa animal, namely the dog is an animal. In the case of vehicles inheriting vehicles, they say that the vehicle ISA completion tool, i.e. the car is a means of transport
      • The rationality of inheritance: quoting a word from "big talk" to describe the succession. "Man is a man who is born with a mother, a demon is born of a demon!"
How to implement inheritance in 3.OC
    • When declaring a subclass, inherit by the name of the parent class, followed by the name of the child class:
@interface 子类名称 : 父类名称@end

12: Object-oriented inheritance of three major features (encapsulation, inheritance, polymorphism)

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.