2 minutes to read UML

Source: Internet
Author: User
Tags dashed line

Do you usually read a little bit far? Analyze articles or design application architectures with minimal interaction with UML class diagrams. In fact, the most commonly used elements in UML class diagrams can be mastered in five minutes, so let's get to know them together:

I. How the properties of a class are represented

In UML class diagrams, a class is represented by a rectangle that contains a class name, an attribute (field), and a method with a split line, such as an employee class that contains the 3 attributes of name,age and email, and the Modifyinfo () method.

What does the plus and minus sign in front of the property/method name mean? They represent the visibility of this property or method, and there are three symbols in the UML class diagram that represent visibility:

· +: Indicates public

· -: Indicates private

· #: Denotes protected (friendly also fall into this category)

Therefore, the employee class in has 3 private properties and a public method.

In fact, the complete representation of a property is this:

Visibility name: Type [= default value]

The content representation in brackets is optional

Method of representation of a class

We have seen the representation of the method. In fact, the complete representation of the method is as follows:

Visibility name (parameter list) [: return type]

Similarly, the contents of the brackets are optional.

For example, in the demo class, 3 methods are defined:

· The public method method1 receives a parameter of type object with the return value type void

· Protected method Method2 No parameter, the return value type is string

· Private method METHOD3 receives a parameter of type int, int[], return value type int

Iii. representation of relationships between classes and classes

1. Association relationship

The association relationship can be further divided into one-way association, two-way Association and Self-Association.

(1) One-way correlation

As we can see, a one-way association in a UML class diagram is represented by a straight line with an arrowhead. Indicates that each customer has an address, which is implemented by having the customer class hold a member variable class of type address.

(2) Bidirectional correlation

It is easy to see that the so-called two-way Association is a member variable that each side holds each other's type. In a UML class diagram, a bidirectional association is represented by a straight line with no arrows. Maintains a product[] array in the customer class, indicating that a customer has purchased those products; Maintaining a member variable of the customer type in the Product class indicates which customer purchased the product.

(3) Self-correlation

A self-association is represented in a UML class diagram with a line with arrows pointing to itself. It means that the node class contains a member variable of type node, which is "self-contained".

2. Aggregation relationship

The car class and engine class are the aggregation relationships (the car class contains a member variable of an engine type). As we can see, the aggregation relationship in UML is represented by a straight line with a hollow diamond and an arrow. The aggregation relationship emphasizes that the "whole" contains "parts", but that "parts" can be separated from the "whole" and exist separately. For example, the car contains the engine, and the engine is separated from the car can exist alone.

3. Combined relationship

The most significant difference between a combinatorial relationship and an aggregation relationship is that the "part" is removed from the "whole" and no longer exists. Like what:

Clearly, the mouth is part of the head and cannot be separated from the head. In UML class diagrams, the composition relationship is represented by a straight line with a solid diamond and an arrow.

4. Dependency relationship

From what we can see, driver's Drive method only comes into play with a car object, so we say that the driver class relies on the car class. In a UML class diagram, a dependency relationship is represented by a dashed line with arrows.

5. Succession relations

The inheritance relationship corresponds to the Extend keyword, which is represented by a straight line with a hollow triangle in the UML class diagram, as shown in, the student class inherits the person class from the teacher class.

6. Interface Realization Relationship

This relationship corresponds to the Implement keyword, which is represented in a UML class diagram with a dashed line with a hollow triangle. For example, the car class and the ship class both implement the vehicle interface.

Here, UML class diagram of the most common representations we have finished, with these we can read the common UML class diagram, the rest of the encounter when you can check.

Iii. references

Http://www.uml.org.cn/oobject/201211231.asp

The original: http://mp.weixin.qq.com/s?__biz=MzIzMjE1Njg4Mw==&mid=2650117683&idx=1&sn= 85e9946c81a5c283a691acfca174d52a#rd

2 minutes to read UML

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.