Object-oriented features

Source: Internet
Author: User

Object-oriented features

In UML, I learned about object-oriented, so I have a preliminary understanding of object-oriented, which lays a good foundation for a more convenient understanding of object-oriented in the future.

Abstract, encapsulation, inheritance, and polymorphism are four basic features of object-oriented technology and constitute the idea of object-oriented programming. It is these features that ensure the security, reliability, and reusability of the program. After development, the application of object-oriented ideas is more extensive, not only software, applications in the fields of hardware, artificial intelligence, distributed computing, and operating systems are becoming more and more important.

Abstraction

Abstract can ignore non-essential features irrelevant to the current target in a thing and emphasize features related to the current target. For example, the globe aims to see the whole picture of the Earth through the globe, regardless of the ratio of the part on the globe to that of the Earth. This is just a model of the earth. The simpler the abstract model and the less characteristic it has, the more common the model will be. By observing the globe, we can find the four oceans on seven continents that we recognize as everyone. We don't have to know the specific appearance of every continent or ocean. We can see it at a glance.

Abstraction can also classify information, divide objects according to certain standards, and implement the layered structure of the abstract model, which is more common and easy to process. In this way, the abstracted class ensures the reuse of objects.

Encapsulation

Binds the State and behavior of an object to form an independent whole and hides the internal details of the object as much as possible. Encapsulation information shielding reflects the relative independence of things and helps protect data integrity. Binding has two meanings: It combines all the states and actions of an object at the moment to form an integral whole. The private attributes of an object can only be modified and read by the object's behavior. The second is to conceal the internal details of the object as much as possible, and the external contact can only be achieved through external interfaces. The encapsulation result is that the internal properties or status of the object cannot be changed at will, and the attribute or state of the object can be changed through the Public Access Controller.

In the object-oriented programming, you cannot blindly limit that the attributes of an object can be directly read from the outside. Otherwise, a lot of useless operations will be added. You need to analyze the attributes of the object before setting it.

Inheritance

There are not only commonalities between various things, but also their own characteristics. If we ignore the characteristics of things, the world will become unchanged and the wonderful world with unique characteristics will be lost. The characteristics and personality of things are the reasons for the stability of the world at this level. These characteristics are also part of the difference between things and complement each other.

In contrast to abstraction, abstraction is to discard the features between things and abstract the commonalities between things into a class. inheritance is to extract multiple classes formed by different features between things, this class has all the features of the previous class. It is a subset of the previous class and forms a hierarchical structure. In this way, we can see that inheritance and abstraction are two inverse processes. abstraction abstracts the common classes from multiple objects and is a process from many to few; inheritance refers to the hierarchy of multiple child classes with their own characteristics from the object class, and is a process from few to many.


In particular, inheritance means "automatic ownership", that is, in a special class, you do not have to re-define the attributes and behaviors that have already been defined in a general class, but the special class is automatic, it implicitly owns the attributes and behaviors of its general classes, and after inheritance, these attributes and behaviors exist on their own. A general class is called a base class, and a special class is called a derived class. For example, the four special categories of primary school students, middle school students, college students, and graduate students are subcategories of the general category of students and new classes inherited from the student category, they automatically have all attributes and methods belonging to the student class, and they also have their own features, so they no longer need to redefine the attributes and methods that have been defined in the student class. The student class is a base class, and the primary school class is a derived class.

Inheritance has the following purposes in the Development of object-oriented software, or can be said to be an advantage: 1. the class description is more concise; 2. ability to reuse and expand existing class library resources; 3. software is easy to maintain and modify.

Polymorphism

Polymorphism refers to the ability of two or more objects of different classes to make different calls to the same message or method. In object-oriented programming, polymorphism refers to the fact that two or more same function names belonging to different classes correspond to different functions with similar functions, you can use the same call method to call these functions with different functions of the same name. This can be understood in this way, there is a method in the base class of a graph that is drawing, and there is also a drawing method in the rectangle of the derived class and the elliptic class of the derived class, but through the same drawing action, the image drawn by the rectangle class is a rectangle, and the image in the ellipse is an ellipse.

The combination of inheritance and polymorphism realizes personalized software design. Abstract and inheritance in object-oriented systems are more important and helpful for understanding object-oriented systems. When you are unfamiliar with object-oriented systems, you can take these two fields as breakthrough points to fully understand object-oriented systems.

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.