Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use UML Class Diagram

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use UML class diagram". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use UML class diagram.

Brief introduction of UML Class Diagram

The class diagram (Classdiagram) shows the static structure of the model, especially the classes that exist in the model, the internal structure of the class and their relationship with other classes. The class diagram does not show temporary information.

A class diagram (Classdiagram) consists of many (static) illustrative model elements (such as classes, packages, and relationships between them, which are interconnected with their contents). Class diagrams can be organized in (and belong to) packages, showing only the relevant content in a specific package.

Class diagrams (Classdiagram) are the most commonly used UML diagrams, showing classes, interfaces, and their static structures and relationships; it is used to describe the structured design of the system.

The most basic elements of a class diagram (Classdiagram) are classes or interfaces.

UML class diagram using

You usually use UML class diagrams in three ways:

1. Model the vocabulary of the system

Modeling the vocabulary of the system is actually discovering the class from the vocabulary and discovering its responsibility.

2. Modeling simple collaboration

Collaboration refers to the behavior that classes, interfaces, and other elements work together to provide some cooperation, which are not simply energized by elements. For example, when you model the transaction process in a distributed system, you can't understand how the transaction works through only one class. In fact, the execution of this process involves the cooperation of a series of classes. Use class diagrams to visualize these classes and their relationships.

3. Model a logical database schema

The imagination pattern is the conceptual blueprint for designing the database. In many areas, you will want to save persistent data to relational databases and live object-oriented databases. You can model these database schemas with class diagrams.

UML class diagram elements:

Class

Interface

Collaboration

Relationship

Like other diagrams, class diagrams can contain annotations and restrictions.

Class diagrams can also include packages and subsystems, both of which are used to group elements. Sometimes you can put an instance of the class in the class diagram later.

Note: component diagrams and distribution diagrams are similar to class diagrams, although they do not contain classes but contain components and nodes respectively.

1. Class (Class)

The class in the UML class diagram generally consists of three components. * is the name of the class; the second is the attributes; the third is the method provided by the class (the nature of the class can be placed in the fourth part; if the class contains an inner class, a fifth component will appear). The part of the class name cannot be omitted, and other components can be omitted.

Class name writing specification: the body word indicates that the class can be instantiated, and the italic character indicates that the class is abstract.

Property and method writing specification: modifier [description information] property, method name [parameter] [: return type | type]

Visibility modifiers that can be appended before properties and methods:

The plus sign (+) indicates that the public; minus sign (-) indicates that the private;# sign means that protected; omits these modifiers to indicate visibility at the package (package) level.

If a property or method has an underscore, it is static.

The description information uses the end.

The nature of a class consists of an attribute, an assignment method, and a value method. The way of writing is similar to that of writing.

two。 Package (Package)

The package in the UML class diagram is a general-purpose composition mechanism. A package in UML corresponds directly to a package in Java. In Java, a package may contain other packages, classes, or both. When modeling, logical packages are usually used to organize the model, and physical packages are used to transform them into Java packages in the system. The name of each package uniquely identifies the package.

3. Interface (Interface)

An interface is a collection of operations that specify the services provided by a class. It corresponds directly to an interface type in Java. There are about two ways to represent an interface. For specific painting methods, see the following example:

4. Relationship

The common relationships in UML class diagrams are: generalization relation (Generalization), association relation (Association), aggregation relation (Aggregation), composition relation (Composition), dependency relation (Dependency).

Among them, polymerization relation (Aggregation) and composition relation (Composition) belong to association relation (Association).

General relations are represented as inheritance or implementation relations (isa), associations as variables (hasa), and dependencies as parameters in functions (usea).

Generalized relationship: expressed as the inheritance relationship between classes, the inheritance between interfaces, and the implementation relationship between classes and interfaces.

Representation: use a hollow arrow + solid line with the arrow pointing to the parent class. Or hollow arrow + dashed line, if the parent class is an interface.

Association: a connection between a class that makes one class know the properties and methods of another class.

Representation: use solid lines + arrows to point to the class being used.

Aggregation relationship: is a kind of association relationship, is a strong association relationship. The aggregate relationship is the relationship between the whole and the individual. The two classes of the association relationship are at the same level, ah, the two classes of the aggregation relationship are at different levels, one is the whole, the other is the part.

Representation: hollow diamond + solid line + arrow, arrow pointing to the part.

Synthetic relationship: it is a kind of association relationship, which is stronger than the aggregation relationship. It requires that the object representing the whole in the ordinary aggregation relationship is responsible for the life cycle of the object that represents the part, and the composite relationship cannot be shared.

Representation: solid diamond + solid line + arrow

Dependency: a connection between classes, indicating that one class depends on the definition of another. For example, if A depends on B, B is represented as a local variable, a parameter to a method, or a call to a static method.

Representation: dashed line + arrow

At this point, I believe you have a deeper understanding of "how to use UML class diagrams". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 261

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report