UML Class diagram detailed

Source: Internet
Author: User
Tags dashed line

When drawing a class diagram, it is important to clarify the relationship between classes and classes. The relationships of a class are generalized (generalization), implemented (realization), dependent (Dependency), and associative (association). The association is divided into general relationship and aggregation relation (Aggregation), synthesis relation (composition). Here we understand these relationships in conjunction with examples.

Basic concepts

Class Diagram: Class diagrams are the most commonly used and most important diagrams in object-oriented system modeling and are the basis for defining other diagrams. Class diagrams are primarily used to display a static model of classes, interfaces, and static structures and relationships between them in a system.

3 Basic components of a class diagram: Class Name, property, method.

Generalization (generalization): Represents the relationship of Is-a, which is the most coupling between objects, and the subclass inherits all the details of the parent class. Direct use of inheritance expressions in languages. In a class diagram, a solid line with a triangular arrow is used, and the arrow points from the subclass to the parent class.

Implementation (Realization): In the class diagram is the relationship between the interface and the implementation. This is nothing to say. In a class diagram, a dashed line with a triangular arrow indicates that the arrow points from the implementation class to the interface.

Dependency (Dependency): One of the weakest associations between objects, is a temporary association. The code generally refers to the call relationships that are established by local variables, function parameters, and return values for other objects. A class calls some of the methods in a dependent class to accomplish some of the duties of this class. In a class diagram, a dashed line with arrows indicates that the arrow is pointing from the class to which it is dependent.

Association (Association): a reference relationship between objects, such as the relationship between a customer class and an Order class. This relationship is typically expressed using the properties of the class. Association is divided into General Association, Aggregation Association and Combinatorial Association. The latter two are analyzed later. In a class diagram, a solid line with an arrowhead is used, and the arrow points from the class that is associated with it. Can be unidirectional and bidirectional.

Aggregation (Aggregation): Represents the relationship of Has-a, which is an unstable containment relationship. Stronger than the general association, there is the relationship between the whole and the local, and there is no whole, local can also exist alone. If the company and the employee relationship, the company contains employees, but if the firm closed, employees can still change the company. In a class diagram using a hollow diamond representation, the diamond is directed from the part to the whole.

Combination (composition): Represents the relationship of Contains-a, which is a strong containment relationship. The combined class is responsible for the life cycle of the grouped classes. is a stronger aggregation relationship. Part can not be separated from the whole existence. If the relationship between the company and the department, without the company, the department can not exist; the relationship between the questions and options in the questionnaire, and the relationship between order and order options. In a class diagram using a solid diamond representation, the diamond is directed from the part to the whole.

Multiplicity (multiplicity): Typically used in association, aggregation, and composition. Is the representation of how many associated objects exist. Use numbers: An asterisk (number) indicates. For example, a cut-off notification can be associated with 0 to n trouble sheets.

Differences in aggregation and composition

These two are more difficult to understand, the point is to say. The difference between aggregation and composition is that the aggregation relationship is a "has-a" relationship, the combinatorial relationship is a "contains-a" relationship, and the aggregation relationship indicates that the relationship between the whole and the part is weaker, and the combination is stronger; The object representing part of the aggregation relationship is independent of the lifetime of the object that represents the aggregation thing. Deleting an aggregation object does not necessarily delete the object that represents the part of the thing. Once the composition object is deleted, the object representing part of the thing is deleted as well.

Example analysis

Unicom Customer response Oss. The system has the function module such as trouble order, business opening, resource verification, cutting, service re-insurance, network quality performance and so on. Now let's take some of the demand as an example.

You can refer to the class diagram and understand it well.

1. Notice is divided into general notice, cut-off notification, re-insurance notice. This is an inheritance relationship.

2. Noticeservice and implementing class Noticeserviceimpl are implementation relationships.

3. Noticeserviceimpl refers to notice through the parameters of the Save method, which is the dependency relationship. The Basedao completion function is also called, and it is a dependency.

4. It is a general association between a cut notification and a fault ticket through an intermediate class (notification circuit).

5. There is an aggregation relationship between the re-insured notification and the Plan library. Because the plan library can be entered in advance, and the re-insurance notification is not necessarily linked, can exist independently. In the system is manually selected from the list. Delete the re-insurance notification without affecting the plan.

6. There is an aggregation relationship between the cut notification and the demand order. Similarly, a demand order can exist independently of the cut-off notification. In other words, delete the cut-off notification, without affecting the demand list.

7. Notifications and replies are a combination of relationships. Because the reply cannot exist independently of the notification. That is, delete the notification, which notifies the corresponding reply to cascade Delete.

After the above analysis, I believe that we have a better understanding of the relationship between the class. Everyone has any other ideas or good ideas, welcome to shoot bricks.

PS: Or that sentence: The above class diagram with Enterprise Architect 7.5 Draw, recommend the EA here, very good. Can replace Visio and rose. The Visio feature is not powerful enough, and Rose is too heavy. Only EA is more appropriate.

UML Class diagram detailed

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.