The Richter substitution principle in C #

Source: Internet
Author: User

The principle of the Richter conversion
Subclasses can assign values to parent class objects
Parent-class objects can be coerced into corresponding subclass objects


The principle of the Richter substitution is intuitively understood to mean that the subclass is the parent class, which in turn does not make sense.
It's like a man is right, but a man is wrong.
That's clear.


In object-oriented thinking, a derived class has all the characteristics that the base class exposes downward, which is a special case of the base class.
When a derived class object is assigned to the base class type, the following occurs: The data structure of the derived class corresponds to the database of the basis class in turn. and the derived class has its own data that will not be visible.

When an object of the base class attempts to convert to a derived type, the data for the base class object cannot be populated in turn all the data structures of the derived class. This causes it to fail to complete the functionality defined by the derived class. The compiler will prompt or even make an error.
This is why the derived class is capable of the base class function, but the base class is not fully qualified for the function of the derived class.
Casting is a base class to a derived procedure: That's because the designer knows that the data structure of the base class object can completely fill out the structure of the derived class. Otherwise, a strong-go error occurs. Generally it is best to avoid the use of strong turn!

Also, it is not entirely true that a subclass can appear where any parent class object appears, and the parent class sometimes does not expose some of its members to subclasses.
C # sample code: HTTP://WWW.EYESOURCECODE.COM/F/CSHARP/1

The Richter substitution principle in C #

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.