Object-oriented Series 3 (polymorphism)

Source: Internet
Author: User

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.


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.