Object-oriented polymorphism. We should first understand the polymorphism in our daily life. In April, the university campus was the busiest month for community activities. At that time, the relevant management departments of the school will approve and issue the "Community activity planning case" submitted by each community. Taking a drama club I participated in as an example, after receiving the approved documents, the President will divide the internal personnel of the whole community into different roles and responsibilities, the scriptwriter department, the logistics department, the external department, the primary department, and the ministry of literature and art all have their own division of labor, and they are actively preparing for each other. In order to complete a joint drama, everyone has done their best.
The "community activity planning case" approved here agrees to run the activity (a command). After receiving the approval documents, the "President" determines that different departments are preparing for the event (each of which implements different operations ). This is polymorphism.
On the day of the drama show, the host announced the official start of the gala. The lighting group-Zhuguang, drama group-moving items, actors group-came to the stage for the performances, respectively. All the highlights are perfectly coordinated and orderly. (You can focus on any part of the project. You can also make an overall overview of all activities)
The following two tables are clearer:
(To be honest, the above content was originally intended to be implemented using code. Unfortunately, it took a long time, and now it has limited capabilities and will be supplemented later)
The above are all embodied polymorphism. If we look at life with object-oriented thinking, there are many examples around us.
Where does object-oriented polymorphism apply?
1. Method
(1) overload (polymorphism during compilation)
(2) virtual method (Runtime polymorphism)
(3) Abstract METHODS (Runtime polymorphism)
(4) Commission
2. Class-Inheritance
3. Interface-inheritance (same-sex)
In general, polymorphism is a manifestation of different responses to the same information.