UML class diagram symbols various relationship descriptions and examples (reprint)

Source: Internet
Author: User
Tags dashed line

Article Source: http://www.cnblogs.com/duanxz/archive/2012/06/13/2547801.html

The ways in which the relationships between objects and classes are described in UML include: Dependency (Dependency), Association (association), Aggregation (Aggregation), composition (composition), generalization (generalization), Implementation (realization) and so on.

  • Dependent ( Dependency ): The change of element a affects element B, but the other is not, so the relationship between B and A is a dependency, B depends on a, and the generic relationship and the implementation relationship are semantically dependent, but because of its more special use, it is described separately. In UML, the dotted line with arrows represents the dependency relationship, and the arrows point to the dependent elements.
  • Generalization ( Generalization ): Often referred to as inheritance (special individual is kind of the general individual) relationship, do not have to explain more. In UML, a solid line with a hollow arrow represents a generalization relationship, and an arrow points to a general individual.
  • implementation ( realize ): Element A defines a convention in which element B implements this convention, then the relationship between B and A is realize,b realize a. This relationship is most commonly used in interfaces. In UML, the realize relationship is represented by a hollow arrow and a dashed line, and the arrow points to the element defining the contract.
  • Association ( Association ): The structural relationship between elements is a weak relationship, and the associated elements can often be considered independently. In UML, solid lines are used to represent association relationships, and arrows point to dependent elements.
  • Aggregation ( Aggregation ): A special case of an association relationship that represents the relationship between a part and a whole (the whole has part a). In UML, a solid line with a hollow diamond head represents a aggregation relationship, and a diamond head points to the whole.
  • Group Hopewell ( composition ): A combination is a variant of the aggregation relationship that represents a stronger composition relationship between elements. If it is a combinatorial relationship, if the whole is destroyed, the individual is bound to be destroyed, and the aggregated individual may be shared by multiple entities, not necessarily destroyed as a whole. In UML, solid lines with solid diamond heads represent composition relationships, and diamond heads point to the whole.

The relationship between dependency (Dependency) is weakest, while Association (association), Aggregation (Aggregation), and composition (composition) represent the relationships in turn. In other words, associations, aggregates, and combinations are all dependencies, and aggregations are associations that indicate the overall and partial relationship between objects, whereas a combination is an aggregation that indicates the same life-cycle relationship between the whole and the part.

The relation and dependency relationship is summed up in a word, the dependency describes the call relationship between the objects, and the association describes the structure relationship between the objects.

The following example will show the relationships independently for a specific purpose. Although grammatically correct, these examples can be further refined to include more semantics within their valid range.

1.1.1 Dependency (Dependency): Dashed arrows indicate

1. Dependency is also the connection between class and class
2, dependence is always one-way. (#add Note that you want to avoid two-way dependencies.) In general, there should be no bidirectional dependencies. )
3. Dependencies are represented in the Java or C + + language as local variables, parameters of methods, or calls to static methods.

Class Person

{

void Buy (Car car)

{

...

}

}

Presentation method: Dashed and arrow

Features: When a class has a usage relationship with a class, it is a dependency, unlike an association relationship, where dependency does not have a "owning relationship" but an "acquaintance relationship" that is only relevant in a particular place (such as a method body)

1.1.2 Association (ASSOCIATION): Solid Arrow indicates

1. An association is a junction between a class and a class that enables a class to know the properties and methods of another class.
2. The association can be bidirectional or one-way (#add还有自身关联). Two-way associations can have two arrows or no arrows, and one-way associations have an arrow.
3. In Java or C + +, association relationships are implemented by using member variables.

Class Apprentice

{

};

Class Tang Monk

{

protected:list< Apprentice > Tdlist;

};

Representation method: Solid Arrow

Characteristics: Represents a dependency between a class and a class or class and an interface, and is represented by an "owning relationship", in which the code can be expressed as an instance variable.

1.1.3 Aggregation (Aggregation): With Hollow Diamond Head

1, the aggregation relation is one kind of correlation relation, is the strong correlation relation.
2, aggregation is the relationship between the whole and part, for example, the car by the engine, tires and other components.
3, the aggregation relationship is also achieved through member variables. However, the two classes involved in an association relationship are at the same level, while in the aggregation relationship, two classes are at different levels, one representing the whole and one representing the part.
4. Correlation and aggregation are indistinguishable only from Java or C + + syntax, and must be examined in relation to the logical relationships among the classes involved.

Class engine

{

};

Class Tires

{

};

Class car

{

Protected: Engine engines;

Protected: Tyre tyre[4];

};

Presentation method: Hollow Diamond Head

Characteristics: belonging to the special Case of association, embodying part-whole relationship, is a weak ownership relationship; The whole and the part can have different life cycle; it is a weak association;

1.1.4 Synthesis (composition): Solid line representation with a solid diamond head

1, the synthesis relation is one kind of correlation relation, is also stronger than the aggregation relation.
2, it requires the ordinary aggregation relationship represents the whole object is responsible for representing the part of the object's life cycle.

Class limb

{

};

Class Person

{

Protected: limb limb[4];

};

Usually a solid diamond plus solid line arrow indicates

Characteristics: belong to the special circumstances of the association, also embodies the part of the whole relationship, is a strong "ownership relationship", the whole and part have the same life cycle, is a strong association;

Generalized Relationships (generalization and implementation): represents an inheritance relationship between a class and a class, an inheritance relationship between an interface and an interface, or a class-to-interface implementation relationship. A generalized relationship is a subclass that points to a parent class, or from a class that implements an interface to an implemented interface, in the opposite direction of inheritance or implementation. As shown in the following:


Figure: Generalized relationships

1.1.5 Generalization (generalization): Solid line representation with hollow arrows

Generalization ( figure H) represents the relationship between a more generalized element and a more specific element. Generalization is a UML element that is used to model inheritance. In Java, this relationship is represented directly by the extends keyword.

A generalization relationship represents an inheritance relationship between a class and a class, and an inheritance relationship between an interface and an interface. Figure h

1.1.6 Implementation (realization): Hollow arrow and dashed line representation

The example ( figure I) relationship specifies a contract between two entities. In other words, one entity defines one contract and the other guarantees the performance of the contract. When modeling a Java application, the implementation relationship can be expressed directly with the implements keyword.

Figure I

UML class diagram symbols various relationship descriptions and examples (reprint)

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.