Basic UML relationships

Source: Internet
Author: User

UML-uniied Model language: a unified modeling language, also known as a standard modeling language. Is a language used to visually model software-intensive systems. The definition of UML includes two elements: UML Semantics and UML notation.
UML is an open method for describing, visualizing, constructing, and writing products of an object-oriented software-intensive system in the development stage. The best application is engineering practice, modeling of large-scale and complex systems, especially in Software
The architecture level has been verified to be valid. The Unified Modeling Language (UML) is a modeling language. Most models are displayed in charts. A typical modeling chart usually contains several blocks or boxes, connecting lines, and attached as a model.
Text used to add information. These are simple but important. They are associated and extended in UML rules.
The construction of UML quickly includes three types:
(1) Things (4 types): Structured things, behavioral things, grouping things, and commenting things
(2) relationship (4 types): generalization, implementation, dependency, and Association (another two special associations: Aggregation and combination)
(3) diagram (10 types): Example diagram, class diagram, object diagram, (package diagram, component diagram) --- construction diagram, deployment diagram, state diagram, activity diagram, sequence diagram, collaboration Diagram
Things are the abstraction of the most representative components in the model. Links combine things. graphs aggregate related things.
The strengths and weaknesses of these links are: generalization = implementation> combination> aggregation> association> dependency.
1. UML relationships
There are six types of UML-defined relationships: dependency, class, association, implementation, aggregation, and combination. Understanding and using these inter-class relationships is the key to understanding and applying UML. These relationships often confuse beginners. Here
The description of the six main UML relationships and class diagrams are given. At first glance, the relationships are clear.
Inheritance (generalization)
Generalization: A class (called subclass and sub-interface) inherits the functions of another class (called parent class and parent interface, and can add its own new function capabilities. The inheritance is Class
The most common relationship between a class or interface and an interface. in Java, such a relationship is identified by the keyword extends, which is generally not controversial during design.

Implementation
Implementation (realization) Relationship: refers to the function of a class to implement interface interfaces (multiple); implementation is the most common relationship between classes and interfaces; in Java, such relationships are identified by the keyword implements,
It is generally not controversial during design;
Dependency
Dependency relationship: A Class A uses another class B, which is contingent, temporary, and very weak, but changes in Class B will affect a. For example, if someone wants to cross the river,
A ship needs to be borrowed, and the relationship between people and the ship is dependent at the code level. Class B is used as a parameter by Class A in a method.
// In Java? .? Dependency :? Local variable ,? Parameters in the method ,? And call static methods

Association
Association: indicates the connection between a class and a class. It allows a class to know the attributes and methods of another class.
Single arrows can be used to represent one-way Association. Double arrows or arrows are not used to represent two-way Association. Bidirectional association is not recommended. There are two endpoints for association, and each endpoint can have a base,
Indicates that the associated class can have several instances.
Common bases and meanings:
0 .. 1:0 or 1 instance.
0 .. *: there is no limit on the number of instances.
1: only one instance is allowed.
1 .. *: there must be at least one instance.
It represents a strong dependency between two classes or between classes and interfaces, such as my friends and I; this relationship is more dependent than the dependency, and there is no dependency relationship.
It is not temporary, generally long-term, and the relationship between the two parties is generally equal, manifested in the Code layer, for the associated Class B to appear in the form of class attributes in the associated Class, it may also be associated classes.
A References a global variable of the associated class B. in Java, the Association is implemented using instance variables.
Aggregation
Aggregation: a special case of association, which is a strong association. aggregation is the relationship between the whole and the individual, that is, the relationship between has-a. At this time, the whole and the part can be separated.
With their own lifecycles, some of them can belong to multiple objects or share multiple objects. For example, the relationship between computers and CPUs, and between companies and employees is manifested in the Code layer, is associated
As a result, it can only be distinguished from the semantic level;
The aggregation relationship is also implemented using instance variables. Java syntax does not allow cross-linking and aggregation.
In an association, two classes are at the same level, while in an aggregation relationship, two classes are at an unequal level. One Class indicates the whole, and the other class indicates the part.

Combination
Composition: it is also a special case of association. It represents a contains-a relationship that is stronger than aggregation, also known as strong aggregation; he also shows the overall and partial
But at this time the overall and part of the relationship is inseparable, the end of the overall life cycle means that part of the life cycle ends; for example, you and your brain; the compositing relationship cannot be shared .. At the code level, and
Associations are consistent and can only be distinguished at the semantic level.
The combination is almost the same as aggregation. The only difference is that "part" cannot exist independently from "whole", that is, the life cycle of "part" cannot be longer than "whole.

Ii. Things
Things in the UML language include four types:
Structured things: Static components of a language. There are 7 types of elements: class and object, interface, active class, use case, collaboration, component, and node.
Behavior thing: a dynamic component of language, indicating the changes and states of things.
Grouping things: the elements and packages of grouping things in the model.
Note: Mark, annotate, and explain the things in the model.
Structured things
Structured things define a physical element in a business or software system and describe the static features of things. Commonly used nouns for structured things. There are 7 types of structured things,
They are: class and object, interface, active class, use case, collaboration, component, node.
1. Classes and objects
A class is an abstraction of the common features of a group of objects with the same attributes, the same operations, and the same relationship. A class is an object template and an object is an instance of a class.
(1) Class Representation
In UML, a class is represented by a rectangle. It contains three areas, the top is the class name, the middle is the class attribute, and the bottom is the class method.
For example, the description of people (class) is graphically represented, as shown in 1.
Assume that the people class contains the following attributes and behaviors:
Class Name: people, in the first column.
Field name: name, age, and field name (also called attribute) are placed in the second column.
Method Name: Speak (), breathe (), Method in the third column

(2). Object Representation
An object is represented by a rectangle. In a rectangle, the attribute name and method name are no longer written, but an object is represented in the format of "Object Name: Class Name" in the rectangle.
For example, figure 2 of the object Zhang lianhai in the class people is shown.
2. Interface
Because the external use of classes (or components) is implemented through the class (or component) method
An interface is a set of operations that provide specific services for a class or component. The interface declares to the outside world that it can provide
. There are two types of interfaces: supply interface and demand interface. Supply interface can only provide
The requirement interface indicates that the class (or component) uses the services provided by other classes (or components.


3. Active class
An active class means that the object created by this class has at least one process or thread and controls the execution of the task through the process or thread.
The expression of the active class is similar to that of the general class, but the outer frame is a rough line description.
As shown in expression 4 of the active class "radio.
4. Use Cases
In the system, a series of actions performed to complete a task to implement a certain function. We call the set of these actions as case instances.
Use Cases describe the common features of a group of use case instances. The relationship between use cases and use case instances is just like the relationship between classes and objects.
The use case is represented by a solid-line elliptic, and the name of the use case is written into the elliptic. For example, use case "User Logon" to indicate 5
5. Collaboration
Collaboration refers to meaningful interaction, that is, interaction between a group of objects to complete a task.
Implementation of Use Cases: Realize the interaction between a group of objects in a use case, that is, to represent the interaction (collaboration) between multiple objects in a use case ). Essentially, collaboration is the implementation of use cases.
Collaboration is represented by a dotted-line elliptic with two columns. For example, when the use case "selling real estate" is represented by "selling real estate" in collaboration, its corresponding representation is 6.

6. Component
Components are also called components: in the system design, a relatively independent software component hides the functional implementation part inside and declares a set of interfaces (including the supply interface and the demand interface ). Therefore, two components with the same interface can be replaced with each other.
A component is a software component larger than a "class", such as a COM component, a DLL file, and an execution file.
The component is usually represented by a rectangle with two small boxes, as shown in figure 7.
7. Nodes
A node is a physical component in a hardware system. It usually has a storage space or processing capability. For example, PCs, printers, and servers are all nodes. In UML, a cube is used to represent a node. As shown in figure 8.
2) behavior
Behavioral things are used to describe interactions between things or changes in the state of things in business systems or software systems. Behavioral things describe the dynamic characteristics of things. Action is represented by a verb. There are two types of behavior things: interaction and state machine.
1. Interaction
Interaction is used to complete the interaction between objects of a task. This function is accomplished by sending and receiving information.
The interaction representation is very simple. A directed line is used to represent the interaction between objects, and a message name is marked on a directed line. 9.
2. State Machine
State Machine (statemachine) migrates an object from one State to another State in the event-driven life cycle of an object,
These State sequences constitute a state machine, that is, a state machine consists of multiple States.
In the UML model, the State is represented as a rounded rectangle and the state name is identified within the rectangle. As shown in, "wait" indicates 10.

3) group things
For a medium or large software system, there are usually a large number of classes, interfaces, and interactions.
To effectively classify and manage structured and behavioral things, you need to group them. In UML
"Package" is provided to achieve this goal. Indicates the graphical symbol of "package ",

4) Comment on things
In the model, the part used to explain other things (text interpretation) is called annotation. A comment is a rectangle folded in the upper right corner. The explanatory text is written in the rectangle. The comment symbol 12 is shown.

Basic UML relationships

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.