UML-class diagram for team communication

Source: Internet
Author: User

 

I. Purpose

It is used to describe the static structure of the system. In all UML diagrams, class diagrams are the most familiar to us. We may have seen them when we are not in contact with UML.

Class diagram, as early as in vs2005, there is a small icon "View class diagram" under "solution Resource Manager", and it also supports "Forward" and "reverse" engineering.

 

<1> Reverse Engineering

First, we define two classes: user and product.

 1   Using  System;  2   Using  System. Collections. Generic;  3   Using  System. LINQ;  4  Using  System. text;  5   6   Namespace  Leleapplication1  7   {  8       Class  Program  9   {  10           Static   Void Main ( String [] ARGs)  11   {  12   13   }  14   }  15   16       ///   <Summary>  17       ///  User class  18       ///  </Summary>  19       Public   Class  User  20   {  21           Public   String Name { Get ; Set  ;}  22   23           Public   Int Age { Get ; Set  ;}  24   25           Public   String Sex { Get ; Set  ;}  26   }  27   28       ///   <Summary> 29       ///  Product  30       ///   </Summary>  31       Public   Class  Product  32   {  33           Public   String Name { Get ; Set ;}  34   35           Public Datetime createtime { Get ; Set  ;}  36   }  37 }

Then, click "View class diagram" to see what the class diagram is like.

<2> Forward Engineering

Since it is a forward project, we can drag some elements on the class designer to see the effect. For details, you can play it on your own.

 

Ii. Basic Elements

1: class chart, enumeration, interface, abstract class, structure, delegate

I have been familiar with these elements and have no good explanation.

2: Link

An association is generally a strong dependency between a class and a class. This relationship is stable and long-term, for example, in C #CodeImplementation: Use a class

For example, I create an order class and use the user class as an attribute of the Order class.

First look at the class diagram:

Then check whether the code is needed:

3: inheritance relationship

Inheritance exists among the three features of OO. We all know the concept of inheritance. How should we present it in class diagrams? We found that in user and Product

Each has a name attribute. According to the OO principle, we need to put forward the name attribute separately, and then let other classes inherit.

Next let's take a look at the generated code to see if it is exactly the same as the class diagram description. (double-click) any class diagram. Hey, is it a little interesting.

Well, we have mastered the class graph 20% so far. You only need to practice more. Of course, you may think the code is too dead,

In actual development, codesmith is often used to solve these boring codes.

There are several relationships to be expressed in the UML class diagram, but there are few practical applications. Well, let's look at the UML class diagram in the "modeling project ".

4: dependency

It is also the relationship between classes, but this relationship is weak and has temporary and unexpected circumstances, which may not be easy to understand,

If you use C # To explain it clearly, in code, a class is generally used as a parameter of the method in another class. Since it is a parameter, you can understand its lifecycle.

5. Aggregation relationship

In the official document, it describes the relationship between "has-a", that is, the relationship between the whole and the Local. If the whole is down, the link fails if it is not found, for example: your power

When the electric appliance is down, the battery inside will be down. Second, we should pay attention that "Hollow diamond" is the overall end, and "Arrow" is the local end.

6: Composite relationship

In the official documentation, it describes"Contains-"The relationship also indicates the relationship between the whole and the local. The whole goes down and the local goes down because they enjoy

A common life cycle. For example, if you are down, your heart will definitely be down. Similarly, "solid diamond" is the whole end.

 

Next, let's look at the slightly more complex class image design of the "Drawing Software". You can also look at your own project class diagram to see if it complies with the OO specification.

 

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.