Class Diagram instances in UML

Source: Internet
Author: User

From: http://blog.csdn.net/onetree2010/article/details/6197463

In Visio, the relationship between the package and the class is the inclusion relationship. After the class is dragged into the folder of the package, the relationship is established. The binary Association symbol can be set to aggregation and synthesis.
Interface: hollow circle + straight line (Tang Lao duck class implements 'talking thup ');
Dependency: dotted line + arrow (relationship between animals and air );
Association: solid line + arrow (Penguins need to know the climate before migration );
Aggregation: hollow quadrilateral + solid line + arrow (relationship between geese and geese );
Synthesis: solid quadrilateral + solid line + arrow (relationship between birds and wings );
Generalization: hollow triangle + solid line (inheritance relationship between animals and birds );
Implementation: hollow triangle + dotted line (interface for Flying Geese );
 
UML class diagram

Explain the UML class diagram:
1. first look at the rectangular box of "animal", which represents a class. This type of graph is divided into three layers. The first layer displays the name of the class. If it is an abstract class, it must be displayed in italic. The second layer is the class features, usually fields and attributes. The third layer is class operations, usually methods and actions. Note that '+' indicates public, '-' indicates private, and '#' indicates protected.

2. the rectangular box of "Flying" represents an interface diagram. The main difference between it and the class diagram is that the interface is displayed at the top. The first line is the interface name, and the second line is the interface method. The interface also has another representation method, commonly known as the lollipop notation, that is, the Donald Duck class implements the "talking" interface.

Interface ifly interface ilanguage
{{
Void fly (); void speak ();
}}
3. animals, birds, ducks, and Donald Duck are inherited relationships. The Inheritance relationships are represented by a hollow triangle + implementation.
 


4. "Dayan" implements the "Flying" interface. The implementation interface is represented by a hollow triangle + dotted line. (Note: The following figure shows a hollow triangle)

Class bird: Animal class widegoose: ifly
{{
// Inherit the animal class // implement the flying Interface
}}
5. Penguins have a great relationship with climate. Penguins need to "know" about climate changes and learn about climate patterns. When one class "knows" another class, you can use the association relationship. The associations are represented by the solid arrow.

 
Class Penguin: Bird
{
Private climate; // The Climate object referenced by the penguin.
}
6. "Geese" and "Geese. Geese are group animals. Each group belongs to one group. One group can have multiple geese. Therefore, the aggregation relationship is met between them. Aggregation indicates a weak "ownership" relationship. It indicates that object A can contain object B, but object B is not part of object. The aggregation relationship is represented by a hollow diamond + solid arrow.

Class widegooseaggregate
{
Private widegoose [] arraywidegoose;
// In the wild goose group widegooseaggregate class, the arraywidegoose array object
}
7. "bird" and "Wings. The relationship between a bird and its wings is like the relationship between the whole and the part, and the life cycle of the wings is the same. Here, the relationship between the bird and its wings is synthetic. Composition is a strong "ownership" relationship, reflecting the strict relationship between the part and the whole, and the same as the overall life cycle. The compositing relationship is represented by a solid diamond + solid arrow. In addition, there is a number "1" and a number "2" at both ends of the link, which is called the base. It indicates that the class at this end can have several instances. Obviously, a bird should have two wings. If a class may contain multiple instances, "N" is used. Association, and aggregation can also have a base.

Class bird
{
Private wing;
Public bird ()
{
Wing = new wing ();
// In the bird class, wing is instantiated during initialization, and both wings are generated simultaneously.
}
}
8. "Animals", "Oxygen", and "water. Animals have several major features, such as metabolism and reproduction. Animals need to have life, oxygen, water, and food. That is to say, animals depend on oxygen and water. They are dependent, expressed by the dotted arrow.
 

Abstract class animal
{
Public bolism (oxygen, water)
{
}
}

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.