In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to understand UML elements and UML diagram symbols, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Let's focus on UML elements and UML diagram symbols. When developing Java applications, developers who want to make effective use of Unified Modeling language (UML) must have a comprehensive understanding of UML elements and how they map to Java.
Introduction to UML element
Class diagram is the most commonly used UML diagram, which is used to describe the structured design of the system. This includes class relationships and the properties and behaviors associated with each class. Class diagrams are an excellent representation of inheritance and composition relationships. In order to use the class diagram as an efficient communication tool, developers must understand how to convert the elements that appear on the class diagram into Java. Let's further explore this conversion process.
In the following sections, we explain the elements of the class diagram and their corresponding representations in Java. I will list the element name, followed by a short code snippet and a diagram to show what the element looks like on the class diagram. This element is briefly summarized in the * * of each section.
Class (Class)
The class (figure A) is the blueprint for the object and 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 "Java" area of figure A.
Figure A
C#:
* Line: the class name, if abstract, is shown in italics.
The second line: field or property.
The third line: the operation of the class (method or behavior).
+: for public;-:: private;#: for protected
Package (Package)
The package (figure B) is a general-purpose combination 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.
Figure B
Interface (Interface)
An interface (figure C) 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 in figure C or 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.
Figure C
C#:
It represents an interface diagram, and the main difference from the class diagram is that it is displayed at the top. The * * line is the interface name, and the second line is the interface method. There is another way to express the interface, commonly known as the lollipop representation, that is, Donald Duck realizes the interface of 'talking to people'. "
UML diagram symbol
The following examples will show the relationships independently for a specific purpose. Although the syntax is correct, these examples can be further refined to include more semantics within their valid scope.
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 (figure D). 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.
Figure D
"there are several major characteristics of animals, such as metabolism and the ability to reproduce. For animals to be alive, they need oxygen, water, food and so on. In other words, animals are dependent on oxygen and water. The relationship between them is Dependency, represented by dotted arrows."
Association (Association)
A structured relationship between entities indicates that objects are connected to each other. The arrow of the associated relationship in the UML diagram symbol 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 (figure E) 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.
Figure E
Aggregation (Aggregation)
Aggregation (figure F) in UML diagram symbols is a form of association that represents the global / local relationship between 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.
Figure F
Synthesis (Composition)
Synthesis (graph G) is a special form of aggregation, 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".
Graph G
Generalization (Generalization)
Generalization (figure H) represents the relationship between a more generalized element and a more specific element. Generalization in UML diagram symbols is an UML element used to model inheritance. In Java, the extends keyword is used to express this relationship directly.
Figure H
Implement (Realization)
The example (figure I) 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.
Figure I
On how to understand UML elements and UML diagram symbols to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.