C # basic series-inheritance 2 (whether polymorphism is overloaded)

Source: Internet
Author: User
Tags types of functions

I have mentioned polymorphism and overload in the previous article. I just checked the information and found that my previous statement is wrong. At first, I was fascinated by Baidu encyclopedia's statement.

Is polymorphism in Baidu encyclopedia overloaded?

In the first statement, one type of overload is polymorphism (such as C ++). There are four forms of polymorphism: 1. virtual function polymorphism 2 template polymorphism 3 heavy load 4 transformation the so-called Dynamic and Static differentiation is another type of polymorphism classification based on the binding time. Strictly speaking, heavy load is the polymorphism at compile time, that is, static polymorphism, different types of functions are called by different names such as int_foo and char_foo during compilation. Therefore, the overload is still consistent with the polymorphism definition-the ability to support different specific behaviors through a single identifier, but the overload is static polymorphism rather than dynamic polymorphism through inheritance and virtual functions. In the second statement, overload is irrelevant to polymorphism, and override is related to polymorphism ). After the derived class re-defines the virtual method of the base class, the base class dynamically calls the corresponding method of the derived class based on the different Derived classes assigned to it, such method calls cannot be determined during compilation. Therefore, the method address is bound at runtime (dynamic binding ). Overload is just a language feature. It is a syntax rule and has nothing to do with polymorphism, and has nothing to do with object-oriented. However, for the second type of overload, there is a special term-rewrite or redefinition. The difference between Overloading and rewriting is whether to overwrite. Rewriting generally occurs between different classes and has inheritance relationships, while reloading is mostly in a class or a piece of code segment.

  

Baidu encyclopedia is under Polymorphism

Polymorphism means that the same entity has multiple forms at the same time. It is an important feature of object-oriented programming (OOD. If a language only supports classes but does not support polymorphism, it can only be indicated that it is object-based, rather than object-oriented. The polymorphism in C ++ is embodied in running and compiling. The Runtime polymorphism is a dynamic polymorphism, And the referenced objects can be determined only at runtime. During compilation, polymorphism is static polymorphism, and the object format can be determined during compilation. In C ++, the following methods are used to realize polymorphism: virtual functions, abstract classes, heavy loads, overwrites, and templates.

  

Msdn C #

Polymorphism is often seen as the third pillar of object-oriented programming after self-sealing and inheritance. Polymorphism (polymorphism) is a Greek term that refers to "multiple forms". polymorphism has two distinct aspects: At runtime, in the location of method parameters, sets, or arrays, the object of the derived class can be processed as the object of the base class. In this case, the object declaration type is no longer the same as the runtime type. The base class can define and implement virtual methods. The derived class can override these methods, that is, the derived class provides its own definition and implementation. When running, the client code calls this method. CLR searches for the runtime type of the object and calls the virtual method override method. Therefore, you can call the base class method in the source code, but execute the derived class version of this method.

  

Msdn VB

"Polymorphism" refers to the ability to define multiple classes with different functions but with the same name. These classes can be used by client code at runtime.

  

No matter C # Or VB, msdn points out that polymorphism is implemented through inheritance. Therefore, overloading is not necessarily a polymorphism.

 

Thank you again, madfrag. I started to write my blog to write what I saw and understand it with my own understanding. This is a good way to help more experts.

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.