When class B inherits from class A, it must be, "class B is class A"?

The book says:

class name has the property last name and first name.

The address is inherited from the name and has the additional property of a street number, street name, city, state, zip code.

It seems different from other cases when

Cat inherits from Animal, and Cat "is-a" Animal.

Is this "is-a" relationship mandatory or required for good object design? Should the address inherit on behalf of?

Update: as some users requested the source: alt text http://img192.imageshack.us/img192/8903/learningrubyp133smaller.png

+3
source share
6 answers

, , Name. , . .

, , - .

, .

+13

, "is-a". Person, - Name Address.

, Address , Name, . , , , .

+4

, . , , "is-a" Name. , Address Name ( ).

+4

. B A, . , , B A.

, , . ( is-a).

, . . , , .

+2

B , A, "is-a" (. ), .
Name ( ), .

+2

: D B, D B.

In C ++: if class D inherits privately from class B, then D is not B, since no one knows. Straustrup thinks of this as an alternative to composition. I consider this one of the mistakes in C ++ design precisely for the reason that, in my opinion, “inherit” should be synonymous with “is a”.

+2
source

Source: https://habr.com/ru/post/1709969/


All Articles