UML Class Diagram

Source: Internet
Author: User
Tags flock

The class diagram is learned by using examples to understand the relationship between classes and classes and the relationship between classes and interfaces.

Start:


Note: There is data on the representation of the interface is divided into: rectangular notation, lollipop notation, in this paper with rational Rose tool drawing,rational rose No rectangular representation of an interface.

Look at the class diagram above three layers: the first layer: Represents the class name. The second layer represents the attributes of a class, usually a field or property. The third layer represents the operation of a class, usually referring to methods and behaviors.

This picture shows that Donald has achieved a speaking interface. In Java code, it is represented as:

The interface is represented by a circle with a realize line connected to the class that implements it.

Interface  language{    void Speak ();}


the graph represents an inheritance relationship, represented by a hollow triangle and a solid line.

Class  Bird extends animal{}
correlation, using the implementation arrows, penguins need to know climate change to understand climate law, and when a class knows another class, it can have an association representation.

Class Penguin extends bird{  private Climate Climate;//References to climate climete objects in penguins. }


Wild geese are social animals, each goose belongs to a flock of geese, a flock of geese can have a number of geese. They belong to the aggregation relationship. The term: aggregation represents a weak "owning" relationship, which shows that a object can contain a B object, but the B object is not part of a object. At first I did not understand this sentence, and later figured out, the wild goose left the Wild Goose group is still an independent individual, from the code may better understand this sentence.

Class widegooseaggregate{  private Widegoose  []  arrarywidegoose;//In the Wild Goose group Widegooseaggregate class, There are wild Goose array object arraywidegoose.
The aggregation relationship is represented by a hollow diamond and an implementation arrow.

Synthesis is also called combination is a strong "ownership relationship" embodies the strict part and the whole relationship, part and the whole life cycle. The lines of the synthetic relationship have numbers representing the cardinality at both ends, indicating that there can be several instances of this class. A bird has only two wings. If a class has countless instances, it is represented by N. Association relationships and aggregation relationships can also have cardinality. Synthetic relationships are represented by solid diamond and solid arrows.

Class bird{privite wing wing;      Public Bird () {      Wing  = new Wing ();//When initializing in the Bird class, instantiate wing, which is generated at the same time.    }}


Animals depend on water and oxygen to survive. They are dependencies and are represented by dashed arrows.

Abstract class bird{public  metabolism (Oxygen Oxygen,water water) {}}

see a good example of analysis, deepen understanding:


With Enterprise Architect 7.5 draw.

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.


generate Java code with the Rational Rose tool:

Note: The tool itself does not reach the generated code correctly.

Step: "1" Select tools (Tools) |java/j2ee| Project specification (item specification) command.

"2" The path added under Classpath, you can choose the target is to generate a Jar/zip file or in a directory

"3" Select tools|java/j2ee| Generate code (Generate code commands to generate the codes).

Take the following class model as an example:

The generated code is as follows:

Source File:c:\\users\\xx\\desktop\\book.javaimport title;public class Book {   private Long bookId;   Private Integer TitleID;   Private String ISBN;   Private String author;   private String publisher;   private String name;   Private Date publishdate;      /**    * @roseuid 548ec70f0019 * * * Public book   ()    {       }}


Reverse engineering is also possible:

To facilitate reverse engineering with the code that was just generated. Select Tool tools|java/j2ee| Reverse Engineer command to reverse engineer.

To avoid the effects, we put the above code:

Source File:c:\\users\\xx\\desktop\\book.java
/**
* @roseuid 548ec70f0019
*/Minus, the last generation is the class model above us.



End


Reference:

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


Note that

Attention:

UML Class Diagram

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.