C # Learning summary ----------------- Polymorphism

Source: Internet
Author: User

I have just opened a blog in the blog field because some of my study notes have benefited me a lot, so I decided to use this platform to record my learning experience from today. I like GIS secondary development, and I will not leave it here in the future. I have accumulated a little bit of programming knowledge, and I have recorded some notes to link my knowledge.

I am reading a book recently, you must know. net, the book covers a lot of content, for c #,. net platform has gradually summarized and gained a new understanding of the scattered things learned in the past. Record some basic things here.

 

Let's talk about polymorphism first:

As mentioned in the book, the key to the inheritance-type polymorphism is the design and implementation of the inheritance system. The book provides a simple Column

Files myFile = new WORDFile ();

MyFile. open ();

MyFile is a parent-class Files variable. It retains the reference pointing to the WORDFile instance of the subclass, and then calls a virtual method Open. The specific call is determined at runtime rather than during compilation. From the perspective of the design pattern, the inheritance polymorphism of the base class embodies a IS-A mode, such as WORDFile IS-A Files is embodied in this inheritance relationship.

Different from the inheritance method of the base class, this polymorphism forms an inheritance system by implementing the method conventions of the interface, which has higher flexibility. From the perspective of the design pattern, the interface implementation polymorphism reflects a CAN-DO relationship. The above file loader can also be implemented in this way

IFileOpen myFile = new WORDFile ();

MyFile. open ();

Multi-state running mechanism:

From the technical implementation point of view, it is the dynamic binding mechanism of. NET that achieves object-oriented polymorphism. Static binding can determine the association during the compilation period, which is generally implemented by method overloading. dynamic binding determines the dynamic Association overwriting method by checking the virtual method table at runtime, it is generally implemented using inheritance and virtual methods.

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.