Object-Oriented Programming has three features: encapsulation, inheritance, and polymorphism.

Source: Internet
Author: User

Object-Oriented Programming has three features: encapsulation, inheritance, and polymorphism. These three features describe object-oriented features from low to advanced. Only when these three features are available can a language be called an object-oriented language. VB also has classes. Its classes also support encapsulation and simple inheritance, but it does not support all inheritance semantics and polymorphism. Therefore, VB can only be called an object-based language.

I. Encapsulation

Encapsulation is a feature of all abstract data types (ADTs). Many people who are new to object-oriented think encapsulation is object-oriented.

Divide the program into multiple cooperative parts according to a certain logic, and provide a stable part (exposing the stable part) to the outside, and hide the changed part, the outside world can only send operation requests to this object through exposed parts to enjoy the services provided by the object, without having to worry about how the object runs internally. This is encapsulation.

Understanding encapsulation is the first step to understand object-oriented, and 40% of programmers only have to understand object-oriented at the encapsulation level.

Ii. Inheritance

Inheritance is also called derivation. In an inheritance relationship, the inherited class is called a base class, And the inherited class is called a derived class or a subclass. Inheritance is the reuse of shared object similarity while keeping objects different. The class that can be inherited always contains the common characteristics of the class of transactions that it abstracts. Inheritance provides implementation reuse. As long as we inherit from a class, we have all the actions of this class. Understanding inheritance is the second step of understanding object-oriented, and 50% of programmers only have to understand object-oriented at the inheritance level. In semantics, "inheritance" indicates that "is a (is-a)" relationship. Many humans inherit the advantages of code reuse, while ignoring the semantic features of inheritance. As a result, many misuse of Inheritance occurs. We will introduce this point later.

Iii. Polymorphism

Polymorphism is a technology that allows users to set a parent object to one or more of its sub-objects with equal sub-objects, the base class object can operate in different ways according to the features of the derived class Object assigned to it "(Charlie Calvert ). Polymorphism expands the adaptability of objects and changes the relationship between a single object inheritance. Polymorphism is the abstraction of behavior, which enables methods with the same name to have different response methods. We can call a method by name without knowing which implementation will be executed, you don't even need to know the type of the object to execute this implementation. Polymorphism is the core concept of object-oriented programming. Only by understanding polymorphism can we understand what is truly object-oriented and truly exert the maximum capability of object-oriented. Unfortunately, only a few programmers can really understand polymorphism.

Relationship between objects

There are two basic relationships between objects: inheritance and combination.

Inheritance relationship

There are two types of inheritance relationships: one is class-to-interface inheritance, which is called interface inheritance; the other is class-to-class inheritance, which is called implementation inheritance. An inheritance relationship is a "generalization/special" relationship. The base class represents general, while the derived class represents special.

Composite relationship.

A combination is the action of combining existing objects into new objects. A combination only repeats the functions of existing programs, rather than reusing them. The difference between combination and inheritance is that it represents the relationship between the whole and the part. For example, a computer consists of CPU, memory, display, and hard disk. These components enable the computer to compute, store, and display graphics, but it cannot be said that the computer is inherited by the CPU.

Reference books: http://www.uml.org.cn/mxdx/200708101.asp

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.