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

What are the constituent elements of UML class diagram

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

Share

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

This article mainly introduces "what are the constituent elements of the UML class diagram". In the daily operation, I believe that many people have doubts about the constituent elements of the UML class diagram. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what are the constituent elements of the UML class diagram?" Next, please follow the editor to study!

UML class diagram elements

1. Class (Classes)

The class contains three components. * are the class names defined in Java. The second is the attributes. The third is the method provided by this class.

Properties and actions can be preceded by a visibility modifier. The plus sign (+) indicates public visibility. The minus sign (-) indicates private visibility. The # sign indicates protected visibility. Omitting these modifiers indicates visibility at the package (package) level. If the property or operation is underlined, it is static. In the operation, you can also list the parameters it accepts, as well as the return type, as shown in the following figure:

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, you usually have a logical package, which is mainly used to organize your model. You will also have physical packages that are converted directly 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. The interface can be represented either by the icon below (the top circle symbol, below the circle symbol is the interface name, the middle is a straight line, and below the line is the method name), or it can be represented by an attached standard class. In general, you can know the relationship with other classes according to what the interface looks like on the class diagram.

UML class diagram relationship:

1. Dependency (Dependency)

A "use" relationship between entities implies that a change in the specification of an entity may affect other instances that depend on it. More specifically, it can be converted to any type of reference to a class or object that is not within the scope of the instance. This includes a local variable, a reference to an object obtained through a method call (as shown in the following example), or a reference to a static method of a class (and there is no instance of that class). Dependencies can also be used to represent the relationship between packages. Because the package contains classes, you can express the relationship between the package and the package according to the relationship between the classes in those packages.

two。 Association (Association)

A structured relationship between entities indicates that objects are connected to each other. The arrow is optional and is used to specify navigation capabilities. If there are no arrows, the implication is a two-way navigation ability. In Java, the association is converted to an instance-scoped variable, as shown in the "Java" area of figure E. You can attach other modifiers to an association. The Multiplicity modifier implies the relationship between instances. In the demonstration code, Employee can have 0 or more TimeCard objects. However, each TimeCard belongs to only a single Employee.

3. Aggregation (Aggregation)

Aggregation in the UML class diagram is a form of association that represents the global / local relationship between the two classes. Aggregation implies that the whole is conceptually at a higher level than the local, while association implies that the two classes are conceptually at the same level. The aggregation is also converted to an instance scope variable in Java.

The difference between association and aggregation is purely conceptual and strictly reflected in semantics. Aggregation also implies that there are no loops in the example diagram. In other words, it can only be an one-way relationship.

4. Synthesis (Composition)

Synthesis is a special form of polymerization, which implies the lifetime responsibility of the "part" within the "whole". Synthesis is also non-shared. Therefore, although the part does not have to be destroyed with the destruction of the whole, the whole is either responsible for keeping the part alive or for destroying it.

Parts cannot be shared with others as a whole. However, ownership can be transferred as a whole to another object, who will then assume lifetime responsibility. The relationship between Employee and TimeCard may be better represented as "synthesis" than "association".

5. Generalization (Generalization)

Generalization in the UML class diagram represents the relationship between a more generalized element and a more specific element. Generalization is a UML element used to model inheritance. In Java, the extends keyword is used to express this relationship directly.

6. Implement (Realization)

The instance relationship specifies a contract between two entities. In other words, one entity defines a contract, while another entity guarantees the performance of the contract. When modeling a Java application, the implementation relationship can be expressed directly with the implements keyword.

At this point, the study of "what are the constituent elements of the UML class diagram" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report