UML Class Diagram

Source: Internet
Author: User
Tags dashed line flock

The first is to review the UML in the understanding of nine kinds of diagrams: http://xhf123456789plain.blog.163.com/blog/static/172880482201192222144421/

Picture use case diagram: http://xhf123456789plain.blog.163.com/blog/static/172880482201192221826110/

The following is an example of a class diagram (as if it were in a big talk design):

Class diagram instances in UML

Interface: Hollow Circle + Straight line (Donald Duck class to achieve ' speaking ');
Dependency: Dashed + arrow (animal and air relationship);
Correlation: Solid + arrows (Penguins need to know the climate before migrating);
Aggregation: Hollow quadrilateral + solid line + arrow (the relationship between Wild Goose and Wild Goose);
Composition/combination: Solid quadrilateral + solid line + arrow (relationship of bird and wing);
Generalization/inheritance: Hollow triangles + solid lines (inheritance relationship between animals and birds);
Realization: Hollow triangle + dashed line (realize the interface of Wild Goose flying);

UML class Diagram

Interpreting UML Class Diagrams:

1. First look at the "animals" rectangle, which represents a class. The class diagram is divided into three layers, the first layer shows the name of the class, and if it is an abstract class it will be displayed in italics. The second layer is the attribute of the class, usually the fields and attributes. The third layer is the operation of the class, usually the method and behavior.

Note that the preceding symbol, ' + ' means public, '-' denotes private, ' # ' represents protected.

2. The "Fly" rectangular box represents an interface diagram, which differs from the class diagram in that the top has the interface display, the first line is the interface name, and the second line is the interface method. Interface there is another way to express, commonly known as lollipop notation, Donald Duck class to achieve the "speaking" interface.

Interfaceifly Interfaceilanguage
{                                             {
Voidfly (); void Speak ();
}                                            }

3. Animals, birds, ducks, Donald Duck they are all inherited relationships, and the inheritance is represented by a hollow triangle + implementation.

4. "Wild Goose" realizes the "Fly" interface. The implementation interface is represented by a hollow triangle + dashed line. (Note: The following figure should be a hollow triangle)

Classbird:animal class Widegoose:ifly
{                                       {
Inherit the animal class//Realize the Flying interface
}                                       }

5. Penguins have a great relationship with the climate, and penguins need to "know" the climate change and need to "understand" the climate law. When a class "knows" another class, an association (association) relationship can be used. The association relationship is represented by a solid arrow.

Class Penguin:bird
{
Private climateclimate;//in Penguin Penguin, referring to the climate climate object
}

6. Two classes of "Wild Goose" and "Wild Goose herd". Wild geese are social animals, each goose belongs to a flock of geese, a flock of geese can have more than a wild goose. So the aggregation (Aggregation) relationship is satisfied between them. Aggregation represents a weak "owning" relationship, which reflects that a object can contain a B object, but the B object is not part of a object. The aggregation relationship is represented by a hollow diamond + solid arrow.

Classwidegooseaggregate
{
Private widegoose[]arraywidegoose;
In the Widegooseaggregate class of wild geese, there are wild Goose array objects Arraywidegoose
}

7. "Birds" and "wings" of the two classes. Birds and wings resemble the whole and part of the relationship, and the wings and the life cycle of the bird are the same, where the bird and its wings are synthetic relations. Synthesis (composition) is a strong "owning" relationship that embodies a strict part-to-whole relationship, as part of the life cycle of the whole. The synthetic relationship is represented by a solid diamond + solid arrow. In addition, there is a number "1" and a number "2" on both ends of the composite connection, which is called the cardinality. Indicates that the class on this end can have several instances, and it is clear that a bird should have two wings. If a class can have countless instances, it is represented by "n". Associative relationships, the aggregation relationship can also have cardinality.

Class Bird
{
Private Wing wing;
Public Bird ()
{
Wing=new Wing ();
In the bird Bird class, when initialized, the wing wing is instantiated, and both of them are generated simultaneously
}
}

8. Between "Animal", "oxygen" and "water". Animals have several major characteristics, such as metabolism, can reproduce. And animals need to have life, oxygen, water and food. In other words, animals depend on oxygen and water. They are a dependency relationship (Dependency), denoted by a dashed arrow.

Abstract class Animal
{
Public bolism (Oxygenoxygen,water water)
{
}
}

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.