generalization

Represents inheritance in Java, with hollow arrows pointing to the parent class

Example:

class Parent {}class Son extends Parent {}Copy the code

implementation

Represents the implementation interface, with the arrow pointing to the interface class

Example:

interface Iter {}class TerImpl implements Iter {}Copy the code

Rely on

To indicate a dependency, a method of one class must depend on another class to be executed. The arrow points to the dependent class

Example:

class A {
    public void testA(a){
        System.out.println("This is category A."); }}class B {
    public void testB(A a){ a.testA(); }}Copy the code

correlation

associated

Represents an association relationship, where the relationship between the two classes is equal

It can be bidirectional, A can be associated with B, and B can be associated with A

The arrow points to the associated class

Example:

class A {
    public void testA(a){
        System.out.println("This is category A."); }}class B {
    private A a;

    public B(A a) {
        this.a = a;
    }

    public void testB(a){ a.testA(); }}Copy the code

The aggregation

Represents an aggregation relationship, which is a special case of association, with no code difference between the two.

One-way association, A can relate to B, B cannot relate to A

The tail is an empty prism, which can also be a straight line

Example:

class A {}class B {
    private List<A> a;
    
}
Copy the code

combination

Represents a combinatorial relation, which is also a kind of association relation

Represents a strong association relationship in which the life cycle of the associated class arises and disappears along with the life cycle of the associated class

Example:

class A {}class B {
    private A a;

    public B(a) {
        this.a = newA(); }}Copy the code

conclusion

The difference between aggregation and combination: aggregation is the individual without the whole, can still exist. Combination means that the individual and the whole cannot be separated, and the individual cannot exist alone without the whole.

Dependency, association and aggregation, composition differences: dependency, association: relationships between classes are at the same level. Aggregation, composition: Relationships between classes are represented as wholes and parts.

The resources

  • Blog.csdn.net/zhuyu714997…
  • zhuanlan.zhihu.com/p/109655171
  • Blog.csdn.net/qq_31655965…