He is a people
He has a head
I am a man is-
I have a woman, has-.
Is_a is used to inherit
Has_a is a combination of classes that contain other classes.
We generally think that inheritance can be divided into two basic forms: Implementation inheritance and interface inheritance.
The main objective of inheritance isCodeReuse:
We found that class B and class C have the same code, so we designed Class A to store common code.
Inheritance based on this idea is called implementation inheritance.
Different interfaces inherit from each other. They are based on the semantics in real life and represent the relationship between ISA:
We believe that both the deposit account and settlement account are sub-classes of accounts. This inheritance is called interface inheritance.
Note that someArticleThe behavior of a class to implement an interface is defined as interface inheritance, which is different from the interface inheritance here. to distinguish between the two concepts, we can use another name inherited by the interface-type inheritance.
The key to inheritance lies in the flexible use of the two inheritance methods.
The meaning of the interface here is different from that in Java or C.
This interface indicates the signature of all public methods in a class.
So the ISA relationship is about behavior.
Hasa relationship, also known as object combination. In fact, there are two hasa relationships.
First, the static hasa relationship. This is called composition in UML, for example, "automobile has-a engine ".
This relationship is similar to aggregation, except that the life cycle of the 'part' is controlled by the 'holistic.
Such control may be direct or transmitted. That is, the 'holistic 'may have direct responsibilities for creating or destroying the 'part', or it may obtain the created part, which will be passed to other assumptions that have responsibilities for it later.
Second, dynamic hasa relationship. This is called aggregation in UML, for example, "airport has-a aircraft ".
Don't forget that use-A is a dependency.