Reproduced UML Class Diagram Summary

Source: Internet
Author: User
Tags italic font

Objective

class diagrams and sequence diagrams are two of the most commonly used diagram in UML. I will make a detailed summary. In many books, or Web sites, when introducing the design of a subsystem of a system, many times, a simple class diagram is given to describe the relationship between the classes that make up the subsystem. This is sufficient to illustrate the importance of class diagrams. The basic understanding of the class diagram has the following two points:

  1. Class diagram is the main purpose of reflecting the structure of the class (attribute, operation) and the relationship between classes, describes the structure of the software system, is a static modeling method;
  2. Classes in class diagrams correspond to the concepts of classes in object-oriented languages and are abstractions of things in the real world. We study the class diagram in more detail based on the above two points.
Basic grammar learning in class diagrams

In UML, drawing each kind of diagram, there is a set of norms, different symbols are different meanings, we should be familiar with the meaning of these symbols in order to understand the meaning of a class diagram. Let's start with a well-painted class diagram, starting with parsing the class diagram:

, this is a very simple class diagram, very simple, but also very familiar. You can see that this class diagram, from top to bottom, is divided into three parts. Yes, the General class diagram is divided into three parts from top to bottom, namely:

  1. Class name
  2. Property
  3. Operation

As you can see, the name of the class diagram above is student, the attribute has name, Sex, age, and the corresponding operation has six. You should know that the student of a class diagram must exist, and that properties and operations are optional. If you see a class without any attributes and operations, don't be surprised, that's right, though not normal. The name of the class has nothing to say, so I start with properties such as the following properties:-name:string If you've seen objective-c, you might not be surprised why there's a minus sign and a plus sign, but, buddy, Here the minus sign and the plus sign and the objective-c meaning are completely different. The plus and minus signs here represent the accessibility of properties and methods, as defined below:

  1. -Indicates private
  2. + indicates public
  3. #表示protected

The name of the property, and the string that follows it, represents the type of the property, so now for-name:string is understandable; it represents a private string-type property defined in the student class name, and for a special case in the diagram: -Age:int=10 Here, int=10, indicates that the default value of the Age property is 10.

The bottom is the operation of the class, the meaning of "+" has been explained. I choose one of the following actions: + Setage (age:int): void operation named Setage, the argument is an int type of age, the return value of the operation is void. Sometimes, we encounter the following syntax: + setage (in age:int): void Yes, more than one in keyword, this keyword indicates that the age parameter is an input parameter, if you see C # words, understand the Out keyword, I think in will not need me to speak more.

Abstract class

Take a look at the following diagram:

You will find that the class name and the Eat method are represented in italic font, and in the class diagram it is also of special significance to indicate that animal is an abstract class, that abstract classes cannot be instantiated, and generally contain at least one abstract operation, such as Eat is abstract.

Interface

Look at this picture:

This is how the interface is represented. What the interface is, not what to explain. This gives you a general understanding of the interface diagram.

Relationships between class diagrams

The basic explanation for the class diagram is here, and then the most important part of the class diagram is the more difficult part to understand: the relationship between the class diagrams. A responsible system, each class is not independent, but the class and the class organized, and the relationship between each class is complex, then how does UML express its relationship?

Inheritance relationship

Inheritance is a basic and important relationship; As for the concept of inheritance, I will not explain it, but only the expression of inheritance in UML.

The above two graphs are representations of inheritance relationships in Astah, and inheritance is represented by a closed, single-arrow solid line pointing to a superclass. This representation is consistent with the generalization representation in the use case diagram, and the unfamiliar friend can take a look at the UML use case diagram to summarize this article.

Association relationship

When the system is modeled, the specific objects will be associated with each other, and the associations themselves need to be clearly modeled, here I will describe the association in 5, about when to use what kind of association, here is not to introduce, here instead will focus on the purpose of each association, and how to show on the class diagram.

Two-way correlation

An association is a connection between two classes, and the association is always assumed to be bidirectional, which means that two classes know each other's relationships and can invoke the other's public properties and methods, although the relationship is applicable in the analysis phase, but I think it is too abstract to describe the class relationships within the design pattern. Because an association relationship must be mapped to an object reference or pointer at design time, the object reference itself is forward. This kind of relationship is less used in the design time, the association is generally the direction.

One-way association in a one-way association, two classes are related, but only one class knows the existence of the relationship. Such as:

A one-way association, represented as a solid line with an open arrow pointing to a known class. Class0 knows the existence of Class1, and Class1 does not know the existence of CLASS0, CLASS0 can invoke the public properties and methods of Class1. When you export code using Astah, one-way affinity is reflected in the inclusion of a Class1 object in Class0.

The concept of association class is a bit difficult to understand, I also refer to the understanding of others, and then make their own understanding, such as:

What is the relationship between person and company? There is an employment relationship, because there is a job that causes the person and company to have a relationship, but when modeling, because the job associates person and company together, It is not appropriate to describe the job Salay in person or company, because different positions have different salary, if the position and salary placed in person, will lead to the person class has a high coupling. So associated with an associated class job, representing the job information. As you can see, the job class is an association relationship and a class that describes the association between a class person and a class company.

Aggregation aggregation is a special type of association that describes the "overall to local" relationship. Basic aggregation in a basic aggregation, the life cycle of some classes is independent of the life cycle of the whole class, such as:

The House is a whole entity, and the window is part of the House, and the window can be created before the building, where the window instance clearly exists independently of the car class instance. Use a hollow diamond representation.

Composite aggregation aggregation is also called containment, but the life cycle of a subclass instance depends on the life cycle of the parent class instance, such as:

The company is a whole entity, the company contains the department, the department cannot exist independently of the company. Represented with a solid diamond.

Self-correlation (reflection Association) is the association itself, you may not think of the meaning of this existence, but you have to imagine that the class can be abstract, when a class is associated with itself, this does not mean that the class instance is related to itself, but one instance of the class is related to another instance of the class, can be expressed as a polypeptide, In UML, it is as shown in the following:

Implementing interfaces

Such as:

In UML, it is very simple to make the solid line in the generalization into dashed lines.

Summarize

This article in general to the UML class diagram to make a summary, usually work involved in the content are generally introduced, if there is anything missing, please point out. At the same time, in this article all the class diagram is used Astah painting, about the use of Astah drawing class diagram, you can refer to: The use of UML tool Astah.

Appendix

Multiple values and their representations

Said Meaning
0..1 0 or 1 x
1 Only one
0..* 0 or more
* 0 or more
1..* 1 or more
3 Only 3
0..5 0 to 5
5..15 5 to 15

Blog turn from: UML Class Diagram Summary

Reproduced UML Class Diagram Summary

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.