Relations in the class of FIG. 6 Detailed

Class Diagram

The following class diagram using PlantUML draw more grammar and usage, please refer to: plantuml.com/ .

Generalization (Generalization)

Used to describe inheritance, use the extends keyword in Java.

@startuml

title Generalization

class Vihical
class Car
class Trunck

Vihical <|-- Car
Vihical <|-- Trunck

@enduml复制代码

Realization relationship (Realization)

It is used to implement an interface, use the implements keyword in Java.

@startuml

title Realization

interface MoveBehavior
class Fly
class Run

MoveBehavior <|.. Fly
MoveBehavior <|.. Run

@enduml复制代码

Aggregation relationship (Aggregation)

Represented by the whole part, but part of the whole and not strongly dependent, there is no part of the whole will still exist.

@startuml

title Aggregation

class Computer
class Keyboard
class Mouse
class Screen

Computer o-- Keyboard
Computer o-- Mouse
Computer o-- Screen

@enduml复制代码

Combination relationship (Composition)

And the polymerization is different in overall composition and are strongly dependent part, the overall absence of a part does not exist. For example, companies and sectors, the company did not exist the department. But the company and the employees belong to the aggregation relationship, because the company is still not the employees.

@startuml

title Composition

class Company
class DepartmentA
class DepartmentB

Company *-- DepartmentA
Company *-- DepartmentB

@enduml复制代码

Association (Association)

It represents the association between different types of objects, which is independent of a state of static relationships, and processes running at the beginning can be determined. It too can be 1 to 1, a plurality of, such a many to many association relationship expressed. For example, students and schools is a kind of relationship, a school can have a lot of students, but only a part of a school student, so this is a relationship of many to one, it can be determined before the start of operation.

@startuml

title Association

class School
class Student

School "1" - "n" Student

@enduml

Dependencies (Dependency)

And relationships are different, the dependency is functional during the operation. Class A and B are dependencies three major forms:

  • A class is a class B of the process of local variables;
  • A class is a class B parameter among the methods;
  • Class A sends a message to Classes B, thus affecting the Class B changes.
@startuml

title Dependency

class Vihicle {
    move(MoveBehavior)
}

interface MoveBehavior {
    move()
}

note "MoveBehavior.move()" as N

Vihicle ..> MoveBehavior

Vihicle .. N

@enduml复制代码



Reproduced in: https: //juejin.im/post/5cfe0563e51d457753138197

Guess you like

Origin blog.csdn.net/weixin_33968104/article/details/93170773