Class Diagram and Its Relationship

Source: Internet
Author: User

1. Class digraphs are graphs showing classes, interfaces, and their static structures and relationships. The most basic unit is a class or interface.
A class chart not only represents the relationship between classes (or interfaces), but also between objects.

The following is a typical class diagram:

(2) attribute list

The attribute can be public, protected, or private package. Powerdesigner may also use +,-, #, and * to indicate: + represents public,-represents private, # represents protected, and * represents package (Java default)

(3) method list

The methods can be public, protected, and private package. The display mode and attributes are the same.

 

2. Relationships in class diagrams

The relationships in a UML diagram are classified into four types: generalization, dependency, association, and implementation. The association can be further divided into aggregation and combination.

1. Generalization)

(1) Generalization: generalization and Generalization

Generalization indicates the inheritance relationship between classes, the inheritance relationship between interfaces, and the Implementation relationship between classes and interfaces. If embodied in the Java language, it is to reflect the extends and implements keywords. The typical class diagram is as follows:

 

(2) Association: Association

An Association describes the connection between a class and a class. It indicates that a class knows the attributes and methods of another class. Associations can be unidirectional or bidirectional. In Java, one-way associations are implemented by holding the reference of the associated object in the form of instance variables. Generally, two-way associations are not recommended. The following is an example of a one-way Association.

 

The above class diagram shows the relationship between the rider and the horse. One instance variable type in rider is horse.

It indicates the 1-to-n relationship between the rider and the horse.

 

(3) aggregation: Aggregation relationship

An aggregate is a part of an association and a very strong association. The aggregation relationship shows the relationship between the whole and the part. For example, the relationship between cars, doors, and engines. :

 

(4) Composition: compose

A composite relationship is also a type of association relationship, which is more enhanced than an aggregation relationship. As mentioned above, an aggregation relationship represents the relationship between the whole and the part. A composite relationship represents an inseparable relationship between the whole and the part based on the aggregation relationship. That is to say, the whole object must be responsible for representing the lifecycle of some objects.

"The whole object is responsible for keeping part of the objects that represent them alive, and in some cases it is responsible for destroying part of the objects that represent them. Objects that represent the whole can sometimes be passed to another object, which is responsible for representing the lifecycle of some objects. In other words, some objects can only form a combination with one object at a time. And the latter is exclusive for its lifecycle ." -- Java and Mode

Let's take the relationship between people and arm as an example. The class diagram of the composite relationship is as follows:

 

(5) Dependency: dependency
Dependency indicates that one class depends on the definition of another class. The dependency is in the single direction. People who eat apple are dependent on apple. The class diagram is as follows:

In general, the dependent object is usually stored in the object in the form of local variables and method parameters. Unlike the association relationship, it does not exist in the object in the form of member variables. This is worth noting. In addition, each dependency has a name. The above dependency is named eats.

Class Diagram and Its Relationship

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.