Article 32: Determining that public inheritance is shaped by is-a relationships, not other relationships

Source: Internet
Author: User

The first consideration is a very typical relationship, that is, the relationship between the rectangle and the square:

1 classrecantagle{2     Virtual voidSetHeight (int);3     Virtual voidSetWidth (int);4     Virtual intHeightint)Const;5     Virtual intWidthint)Const;6     ...7 };8 voidMakebigger (Recantagle &R)9 {Ten     intOldHeight =height (); One setwidgth (WID); AASSERT (height () = =oldheight); -}
The above makebigger mainly to ensure that the process height in the Makebigger, will not be changed. But in the inheritance system, when a square width changes, the height will also be changed, so the above inheritance is actually unreasonable. So in some ways, the usual in our eyes may be rightfully sensible in fact in the inheritance system does not necessarily be able to achieve. The main problem here is that not a rectangle has properties that exist for a square, so what we call a square is a rectangle that is actually just an is-a relationship in English rather than a is-a relationship in the actual inheritance system. Summary: "Public" inheritance means is-a relationship, based on everything on Base-class should be set up on the Derived-class

Clause 32: Determine that is-a relationships are molded in public inheritance and not other relationships

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.