Relationships defined by uml class diagrams

Source: Internet
Author: User

There are six types of uml-defined relationships: dependency, class, association, implementation, aggregation, and combination. The definitions and representation methods are described in the following sections.

Dependency: Changes in element A affect Element B, but vice versa. The relationship between B and A is dependent on; similarity and implementation relationships are also dependency in semantics. However, they are described separately for their special purposes. In uml, the Dependency relationship is indicated by the dotted line with arrows, and the arrows point to the depended element.

Generalization. In uml, a solid line with a hollow arrow is used to represent the Generalization relationship. The arrow points to a general individual.

Implementation: Element A defines an agreement. If element B implements this convention, the relationship between B and A is Realize and B Realize. This relationship is most commonly used in interfaces. In uml, hollow arrows and dotted lines are used to represent the Realize relationship. Arrows point to elements that define conventions.

Association: the structural relationship between elements. It is a weak relationship. The associated elements can be considered independently. In uml, a solid line is used to indicate the Dependency relationship. The arrow points to the depended element.

Aggregation: a special case of an association, indicating the relationship between the partial and the whole (the overall has a part. In uml, the solid line with a hollow diamond header is used to represent the Aggregation relationship, and the diamond header points to the whole.

Composition: A combination is a variant of the aggregation relationship, indicating a stronger combination relationship between elements. If it is a composite relationship, if the whole is damaged, the individual will be damaged, while the aggregated individual may be shared by multiple entities, it may not be damaged as a whole. In uml, a solid line with a solid diamond header is used to indicate the Composition relationship, and the diamond header points to the whole.

Link

The following examples show various relationships for a specific purpose. Although the syntax is correct, these examples can be further refined to include more semantics within their effective scope.

Dependency)

An "use" Relationship between entities implies that after a specification of an object changes, other instances dependent on it may be affected (Figure D). More specifically, it can be converted to any type of reference to a class or object not in the instance scope. This includes a local variable that references an object obtained through method call (as shown in the following example ), or reference a static method of a class (there is no instance of that class at the same time ). You can also use "dependency" to indicate the relationship between packages. Because the package contains classes, you can express the relationship between packages and packages based on the relationships between classes in those packages.

Figure D


Association)

A structured relationship between objects indicates that objects are connected to each other. The arrow is optional and is used to specify the navigation capability. Without arrows, it implies a two-way navigation capability. In Java (Figure E) To an instance scope variable, as shown in the code in the "Java" Area in Figure E. You can append other modifiers to an association. The Multiplicity modifier implies the relationship between instances. In the Demo code, the Employee can have 0 or more TimeCard objects. However, each TimeCard only belongs to a single Employee.

Figure E

Aggregation)

Aggregate (Figure FIs a form of association, representing the overall/local relationship between two classes. Aggregation implies that the whole is at a level higher than the local level, while association implies that two classes are at the same level in concept. Aggregation is also converted to an instance scope variable in Java.

The difference between Association and aggregation is purely conceptual and strictly reflected in semantics. Aggregation also implies that there is no loop in the instance diagram. In other words, it can only be a unidirectional link.

Figure F

Composition)

Synthesize (Figure G) Is a special form of aggregation, suggesting that "local" is responsible for the lifetime of the "whole. Synthesis is not shared. Therefore, although local data may not be destroyed as a whole, it is either responsible for local survival or destruction. It cannot be shared with other entities. However, ownership can be transferred to another object as a whole, and the latter will assume the responsibility for survival.

The relationship between Employee and TimeCard may be more suitable for "merging", rather than "associating ".

Figure G

Generalization)

Generalization (Figure H) Represents the relationship between a more general element and a more specific element. Generalization is a UML element used to model inheritance. In JavaExtendsKeyword to directly represent this relationship.

Figure H


Implementation)

Instance (Figure I) Link specifies a contract between two entities. In other words, one entity defines a contract, and the other entity guarantees the performance of the contract. When modeling Java applications, the implementation relationship can be directly usedImplementsKeyword.

Figure I

After reading: Through java code and uml, you can clearly understand these relationships. Association is divided into three types for comparison, mainly to clarify the dependency, association, generalization, and implementation relationships.

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.