UML class diagram (1.3)

UML: Unified modeling Language Unified Modeling Language

UML class diagram: for a relationship between the classes and the classes included in the system described.

Drawing tools: https://www.processon.com


6 kinds of relationships between the classes and the representation:

6 kinds of dependence relationship can be referred to, according to the kind of relationship is subdivided five kinds.

Code conversion method between the class diagram

class Person
{
    private String name;
    private String Email;
    private  Integer age;
    public void setName(String name)
    {
        this.name=name;
    }
    public void setEmail(String email)
    {
        this.email=email;
    }
    public void setAge(String age)
    {
        this.age=age;
    }
}

Dependence (dependence)

And uses a class B class A, then class A B dependent. (Lack of compile-time type B can not pass)

Generalization (generalization)

Generalization == inheritance. [Dependency] special case

Realization (Implementation)

Relationship implemented as classes and interfaces. Constitute a class implements an interface to realize the relationship. [Dependency] special case

Association (Association)

Properties and methods of a class knows another class. [Dependency] special case

Polymerization (Aggregation)

And part of the overall relationship, can be separated from the whole part. [Relationship] special case

Combination (Composition)

The relationship between whole and part of a whole and can not be separated parts.

For example, the computer may not have a keyboard without a mouse, but not without the CPU, the power can not. Then the keyboard and the computer is an aggregation relationship, separable, but the power supply, CPU is an integral part of the computer.

class Computer
{
    //聚合关系
    private Keyboard keyboard;
    private Mouse mouse;
    
    //组合关系
    private Power power = new Power();
    private CPU cpu = new CPU();;
    
}

class Keyboard
{
    
}
class Mouse
{
    
}

class Power
{
    
}

class CPU
{
    
}


Guess you like

Origin www.cnblogs.com/noneplus/p/11333049.html