Long shengjiu Zi
---- Polymorphism
Author: HolyFire
Each child is different. The truth is that no two or more things in the world are identical. Things have the same and similar sides, and of course they have different sides. Only when different and identical items are taken into account can we fully express things.
The attributes of things have different aspects. We know that one way for people to perceive things is to observe and recognize objects with responses to different lights. Therefore, we give an attribute and color of things. Sometimes the color of some objects is fixed, and the white clouds, blue skies, and green lawns cannot help but make people swim too much.
However, there are some aspects that are uncertain. There is a saying: "The moon is overcast and clear, and people have joys and sorrows." This is not enough to explain this truth. Sometimes we omit some parts in Chinese. "Have you eaten today ?" What is it, "Breakfast", "Afternoon Tea", "Bread", I don't know. Here we will abstract the food. This sentence can be said in the morning, at noon, at night, any suitable time period can be said. We don't know what to eat or when to eat, but we can use it to express your greetings. In this way, you can easily show your specific usage in the environment you need. It is widely used in your daily life. "I cut !" Express what a person wants to do and what to cut. Only interested people will pay attention to it. "I'm ill ." It expresses a person's status. What disease does it have? It's not what everyone wants to know.
Polymorphism refers to different aspects of things
Polymorphism is a complex application and it is difficult to fully elaborate it. Therefore, understanding its ideas becomes the focus. In different situations, we use different methods to achieve polymorphism.
Do you still remember the virtual functions in C ++? As I mentioned in "post-entry-based-virtual functions", virtual functions can be dynamically changed and can be used to achieve our purpose. Different languages use different methods. The implementation mechanism is that interfaces provided by a type can be changed. In this way, we can reflect different ideas.
For better understanding, we use C ++ to implement an example.
We know that to live, we need to work. Work is a social activity of people, and almost everyone is working. There are all kinds of people in the world. What is the difference between people's work? That is, their profession. People in different occupations do different things.
A student's job is to learn, a driver's job is to drive, a hawker's job is to sell goods, and a programmer's job is to write code.
Now, let's analyze that there are many people in the world who want to work.
Persons {work = undetermined}
Students work to learn
{Student, work = study}
The driver's job is to drive
Driver {persons, work = driving}