Class Diagram in UML

Source: Internet
Author: User

Class digraphs are the most commonly used diagrams in UML.

A class, which is a rectangle at a distance and a rectangle at a closer look, but sometimes a rectangle or a set of two or three rectangles.

A class usually has some attributes and methods. The class diagram is shown as follows:

This class chart consists of three rectangles, including class names, attributes, and methods. The previous ("+") signs indicate public attributes or methods (public), ("-") Signs Indicate private attributes or methods (private), and ("#") protection (protected ).

Of course, some hide one or two attributes and methods to make the class graph concise.

Class graph does not mean that you can draw a rectangle and write the name, attributes, and methods. In actual software system development, classes do not exist independently, and there is a certain relationship between classes.

1.Association:

It is a structured relationship used to indicate the relationship between a Class Object and another class object, such as students and teachers, children and parents.


For example, gangge and yunjie are classmates.


In UML, an association includes the following relationships:

(1)Bidirectional Association: Both parties know the existence of the other party and can call the Public attributes and methods of the other party. The two ends do not contain arrows.

For example, Zhigang and yunjie are two-way associations, that is, yunjie knows both gangge and yunjie.

 

(2)Unidirectional Association: Represents a unilateral acquaintance relationship: one-way Association is represented by an arrow with an implemented header.

For example, gangge and Bill Gates, gangge knows Bill Gates, while Bill Gates does not know the existence of gangge.

 

(3)Aggregation relationship: Represented by a hollow diamond, which is weak.

For example, if the CPU and computer do not have a computer, the CPU can still exist independently.


(4)Combination: It is represented by a solid diamond. It is a type of strong inclusion and stronger than aggregation.

For example, the most typical thing is the human and his own arm. If a person does not have one, his arm will disappear, and his arm cannot exist as a single individual.


 

PS: the relationship between aggregation and combination belongs to the whole and part.

2. Generalized relationship:

Describes the type of a class that is another class. A subclass inherits the relationship between attributes and methods of the parent class. For example:

Both basketball and football are ball games. They both have ball attributes (circle) and methods (shooting and playing)

For example, basketball
Is a ball. This kind of relation containing is a is generally an inheritance relation.

3. Dependency: Is a usage relationship. The change of a specific thing may affect other things that use it.

For example, in system development, if we use some public classes for other classes, if these public classes have problems, other classes that call these public classes will also have problems. In UML, the dependency is shown as follows:

4. Implementation relationship: Refers to the relationship between objects implementing an interface. For example, a bird belongs to a bird and implements this interface for birds to fly, so the bird can also fly in the air.

For example, to draw a class diagram using UML, follow these three steps:

First, define the class, then define the class attributes and methods, and finally distinguish the relationship between the class and the class.

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.