UML class diagram

Source: Internet
Author: User

UML class diagram

Using UML class diagrams, we can express the static content of classes and their relationships. In the class diagram, we can show the member variables and member functions of the class, as well as the inheritance and reference relationships between classes. In short, we can depict all source code-level dependencies between classes. In UML, a class is represented:

 

 

The variable and the symbol before the function name in the class diagram. The hyphen (-) indicates private, the pound sign (#) indicates protected, and the plus sign (+) indicates public. The types of variables and function parameters are displayed after the colon (:) after the variables and parameters. Similarly, the return value of the function is displayed after the colon following the function.

The main relationships of classes in UML are dependency, association, aggregation, combination, and generalization (inheritance ).

Dependency:

In UML, the graphical representation of dependencies is a dotted line + arrow, and the arrow points to the dependent class. In program code, dependent classes are often declared as parameters of member functions, it is not declared as a member variable of the class. For example:

 

 

Association:

In UML, the associated graphic representation is a solid line + arrow, and the arrow points to the associated class. In program code, A class with associations is often declared as a member variable of the reference type of the class. For example:

Aggregation:

In UML, the aggregated graphic representation is a hollow diamond + solid line + arrow, and the arrow points to the class to be owned. Aggregation is a special form of association, which implies the overall/partial relationship, however, the other party is not the only one of its own relationships. UML provides us with a very simple rigid rule on clustering: The whole cannot belong to its components. For example:

Combination:

In UML, the aggregated graphic representation is solid diamond + solid line + arrow, and the arrow points to the owned class. The composite relationship in UML refers to the strict relationship between the two classes, it is generally the relationship between the whole and the part, and the other party is the only one of its own. This is the same as associated classes and aggregated classes. The difference is that the class cannot be shared by other classes in the composite relationship, so the life cycle of the class is completely controlled by the class. For example:

Generalization (inheritance ):

All arrows in UML point to the source code dependency. Therefore, arrows point to the base class. Be very careful when using arrows in UML. If arrows are careless, it may be difficult to tell whether they are inheritance or association. For clarity, the inheritance relationship is always drawn vertically, draw a horizontal join. For example:

The interface inheritance relationship is called implementation, and the connection line uses dotted lines, such:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.