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

Get started quickly with UML

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

What is UML?

UML definition:

Unified Modeling language (Unified Modeling Language, UML) is a non-proprietary third generation modeling and specification language.

UML features:

UML is an open method for illustrating, visualizing, building, and writing a developing, object-oriented, software-intensive system artifact. UML presents a series of best engineering practices that have been proven effective in modeling large-scale, complex systems, especially at the software architecture level.

A total of 14 icons are defined in UML2.2, which are roughly divided into three categories:

Structured graphics: emphasize systematic modeling behavioral graphics: emphasize event interactive graphics triggered in the system model: belong to a subset of behavioral graphics and emphasize the data flow in the system model

1. Structural graphics:

Static diagram (class diagram, object diagram, package diagram) implementation diagram (component diagram, deployment diagram) section diagram composite structure diagram

two。 Behavioral graphics:

Activity diagram, state diagram, use case diagram

3. Interactive graphics:

Communication diagram interaction overview diagram (UML2.0) sequence diagram (UML2.0) time diagram (UML2.0) UML class diagram:

Class diagram (Class Diagram): used to represent the static relationship between classes, interfaces, instances, etc., although the name is class diagram, but there are not only classes in the class diagram. Let's take a look at a more comprehensive UML class diagram:

First of all, you can see an "animal" rectangle at the top of the diagram, which represents a class. The class diagram is divided into three layers. The first layer is the name of the class. If it is an abstract class, the class name will be represented in italics. The second layer is the properties of the class, that is, the fields or variables of the class. The third layer is the behavior of the class, that is, methods or functions.

The "Flying" in the lower left corner of the picture represents an interface diagram, which is mainly different from the class diagram in that there is at the top of the interface diagram. Naturally, the first layer is the name of the interface, and the second layer is the interface method. There is another representation of the interface, that is, the lollipop representation in the figure.

Then let's briefly talk about the relationship between the subclass and the parent class and the implementation class and interface in the UML class diagram:

When there is an inheritance relationship between a class and a class, it is represented by a hollow triangle and a solid line, while when a class implements an interface, it is represented by a hollow triangle and a dotted line, whether it is an inheritance relationship or an implementation relationship. The triangle arrow points from the subclass to the parent class or interface.

The relationship between classes and their representation in the UML class diagram, association relationship:

When one class "knows" another class, they have an association, which is represented by a solid arrow. For example, the penguins in the picture need to know the category of climate, and there is a relationship between penguins and climate.

Aggregation relationship:

The two categories in the picture are geese and geese. We all know that geese are gregarious animals, and multiple geese can aggregate into a flock of geese, so the relationship between them is satisfied. Aggregation represents a weak "ownership relationship", which means that An objects can contain B objects, but B objects are not part of An objects. Aggregation relationships are represented by hollow diamonds and solid line arrows

Composite (combinatorial) relationship:

Synthesis is a strong "ownership" relationship, which embodies the strict relationship between the part and the whole, and the part is the same as the life cycle of the whole. The bird in the picture above and its wings are combined, because they are the relationship between the part and the whole, and the wings and the bird's life cycle are the same. Synthetic relationships are represented by solid diamonds and solid line arrows. In addition, there is a number 1 and a number 2 at both ends of the connection of the composite relationship in the diagram, which is called the cardinality, indicating that there can be several instances of the class at this end. Obviously, a bird should have two wings, so the base number of wings is 2. If a class may have countless instances, it is represented by n. In addition to synthetic relations, correlation relations and polymerization relations can also have cardinality.

Dependencies:

We all know that animals have to metabolize in order to maintain life, so they need oxygen, water and other substances. In other words, animals depend on oxygen and water. So there is a dependency between them, represented by dotted arrows.

Then let's look at the class diagram of a single class:

The same from top to bottom are class names, attributes, and behaviors. Attributes and behaviors are preceded by permission representations, with + for public,-for private, # for protected, and ~ for default. The underlined representation of static in attributes and behaviors, that is, static properties and methods.

The Java code corresponding to this class diagram is as follows:

Public abstract class StudentClass {public String name; private int age; protected double weight; double height; public static char sex; public void eat (String food) {} protected void drink () {} private void walk () {} void run () {} public abstract void study (); public boolean openMac () {return true;} public static void playGame () {}} memory skills

Here are some memory techniques for simple UML class diagrams:

Memory skills 1:UML Arrow Direction:

Point to the parent class from the subclass

Some people may think that the subclass is based on the parent class, and the arrow should point from the parent class to the subclass. But we all know that when defining a subclass, we need to specify the parent class through the extends keyword, then the subclass must know the definition of the parent class, and can point to each other only if we know the information of the other party, while the parent class does not know how the subclass is defined, so the arrow direction should point from the subclass to the parent class.

Memory skill 2: solid line-inheritance | dotted line-implementation:

Hollow triangular arrow: inheritance or implementation: solid line-inheritance, is a relationship, extension purpose, so not virtual, very strong dashed line-implementation, dashed line is "dashed" because there is no entity, because the interface needs to be implemented.

Memory skill 3: solid line-relevance | dotted line-dependence:

Dotted line-dependency relationship: temporarily used, if distant, illusory, if nothing, so it is a dotted line, indicating a usage relationship, one class needs to use another class to achieve its function. Generally speaking, a function in a class uses another class as a parameter, or returns a real line-association relationship: a stable relationship, a solid relationship, a buddy, indicating that one class object is associated with another class object. usually there is another class object in a class as a property.

Memory skill 4: hollow diamond-polymerization | solid diamond-combination:

We can imagine that a diamond is a vessel that holds things (such as a plate, or a collection container in the code), and aggregation means that a lot of the same things can be put together in an empty container (the class indicated by the direction of the arrow), so it is the relationship between the whole and the part, which has an independent life cycle, a has a relationship, and a weak relationship, which represents the existence of an entity structure in the vessel. It can be said that the relationship between life and death is the relationship between the whole and the part. Compared with the aggregate relationship, the relationship is stronger. The two have the same life cycle, and the relationship of contains-an is strong.

Memory skill 5: common cardinality expression and meaning, assuming that there are Class An and Class B, digital markers at one end of Class A:

At a certain time in the system, an instance representing Class B can be associated with 0 or 1 instance of Class A, and an instance representing Class B can be associated with 0 or more instances of Class A. an instance representing Class B can be associated with 0 or more instances of Class A, and an instance representing Class B can be associated with one instance of Class A. 1: there can only be one instance. An instance representing Class B can be associated with one instance of Class A. At least one instance, and an instance representing Class B can be associated with one or more instances of Class A.

Note: ".." is usually omitted. Direct use of digital representation

UML sequence diagram:

Time sequence diagram (Sequence Diagram): a diagram showing the interaction between objects arranged in chronological order

The main modeling elements included in the timing diagram are:

Object (Actor) lifeline (Lifeline) control focus (Focus of control) message (Message)

Let's take a look at a simple timing diagram, with the code on the left and the timing diagram on the right:

The three boxes in the sequence diagram on the right represent three instances: Client, Service, and Device, while the dotted line below is the lifeline of the instance. Time passes from top to bottom, and the lifeline only exists in the lifecycle of the instance. The slender rectangle on the dotted line indicates that the instance is in some kind of activity, which is called control focus. The black solid arrow represents the synchronous call to the method, the asynchronous call is the solid non-solid arrow, and the dotted non-solid arrow indicates the end of the method to return. The elements represented by these arrows are messages, such as work and open in the figure.

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: 0

*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

Internet Technology

Wechat

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

12
Report