Location>code7788 >text

UML Class Diagrams

Popularity:74 ℃/2024-08-28 17:57:54

UML class diagram

UML Class Diagrams are static structural diagrams that describe a collection of classes, class attributes, and relationships between classes of a system, which can simplify the understanding of the system.UML Class Diagrams are an important artifact of the analysis and design phase of a system, and are an important model for coding and testing the system.

icon

resemble

analyze

A rectangular box with rounded corners, which represents a class.

The class diagram is divided into three layers:

  • The first level shows the name of the class, in italics if it is an abstract class
  • The second layer is the characteristics of the class, which are usually fields and attributes
  • The third level is the operation of the class, usually a method or behavior.
    • Note the preceding symbols:
      • '+': indicates public
      • '-': indicates private
      • '#': indicates protected

connector

analyze

Rectangular frame with << at the topinterface>> shows that the first line is the interface name and the second line is the interface method.

Attention:There is another way to represent interfaces, commonly known as the lollipop representation. For example, the Donald Duck class in the following figure implements the "Speak Human" interface.

UML Relationships

1. Succession

Description:Inheritance relationships are represented by hollow triangles + solid lines.

Examples:Object-oriented has said that inheritance is an "is a " relationship, and that a bird is one of the animals

2. Realization

Description:The implementation interface is represented by a hollow triangle + dotted line.

Examples:The Goose implements the Fly interface, which defines the methods that the Goose flies.

3. Associations

Description:Relationships are represented by solid arrows

Examples:Penguins and climate are two classes, penguins are very special birds that can swim but not fly. More importantly, it has a strong connection to climate. We will not discuss why there are no penguins in the Arctic and why they have to travel long distances every year. In any case, penguins need to know about the changes in "climate", and they need to understand "climate" patterns. When one class "needs to know" about another class, it can be expressed as an association.

4. Polymerization

Description:Aggregate relationships are represented by hollow diamonds + solid arrows.

Examples:Geese are flock animals, each goose belongs to a flock, and a flock can have more than one goose. A flock can have more than one goose, so they satisfy the Aggregation relationship. Aggregation represents a weak "owning" relationship, where an object A can contain an object B, but the object B is not a part of the object A.

5. Combinations

Description:The combinatorial relationship is represented by a solid rhombus + a solid arrow.

Examples:Combination is a strong "owning" relationship, reflecting a strict part-whole relationship, where the part and the whole have the same life cycle. A bird and its wings are combinatorial (synthetic) relationships because they are part and whole relationships and the wings and the bird have the same life cycle.

Also, you'll notice that the synthetic relation has a number '1' and a number '2' at either end of the connecting line, which is called the cardinal number. It indicates that the class at this end can have several instances; obviously, a bird should have two wings. If a class may have an infinite number of instances, it is denoted by 'n'. Associative and aggregative relationships can also have cardinality


6. Dependence

Description:Dependency, indicated by a dotted arrow

Examples:For animals to be alive, they need oxygen, water, and food dependence