Diagram of six UML class diagram relationships

Source: Internet
Author: User

In the process of learning UML class diagram, UML class diagram relation is a problem that must be mastered, and there are six kinds of relationships in UML definition: dependency, genus, association, implementation, aggregation and combination. The definitions and representations of the methods are described below.

Introduction to UML class diagram relationships

Dependency (Dependency): The change of element a affects element B, but vice versa, then B and A are dependent, B depends on a, the generic relationship and the implementation relationship are semantically dependent, but are described separately because of its more special purpose. In UML, the dotted line with arrows represents the dependency relationship, and the arrows point to the dependent elements.

Genus (generalization): Often referred to as inheritance (special individual iskindof general individual) relationship, need not 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,brealizea. This relationship is most commonly used in interfaces. UML uses hollow hollow arrows and dashed lines to represent realize relationships, with arrows pointing to the elements that define conventions.

Association (Association): a structural relationship between elements, which is a weak relationship in which the associated elements can often be considered independently. In UML, solid lines are used to represent dependency relationships, and arrows point to dependent elements.

Aggregation (Aggregation): A special case of an association relationship that represents a relationship between a part and a whole (the whole Hasa part). In UML, a solid line with a hollow diamond head represents a aggregation relationship, and a diamond head points to the whole.

Composition (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. A solid line with a solid core diamond Head is used in UML to represent the composition relationship, and the Diamond Head points to the whole.

A detailed description of UML class diagram relationships

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.

Dependency (Dependency)

A "use" relationship between entities implies that the specification of an entity changes and may affect other instances that depend on it (Figure D). More specifically, it can be converted to any type of reference to a class or object that is not within the scope of the instance. This includes a local variable, a reference to an object obtained through a method invocation (as shown in the following example), or a reference to a static method of a class (without an instance of that class). You can also use dependencies to represent the relationship between packages and packages. Because the package contains classes, you can represent the relationship between packages and packages based on the relationships between the classes in those packages.

Figure D

Association (Association)

A structured relationship between entities in a UML class diagram relationship indicates that the objects are interconnected. The arrows are optional and are used to specify navigation capabilities. If there are no arrows, hinting is a two-way navigation capability. In Java, the Association (Figure E) is converted into a variable of an instance scope, just as the code shown in the Java area of Figure E. Additional modifiers can be attached to an association. The multiplicity (multiplicity) modifier implies a relationship between instances. In the model code, an employee can have 0 or more timecard objects. However, each timecard only belongs to a single employee.

Figure E

Aggregation (Aggregation)

Aggregation (Figure F) is a form of association that represents a global/local relationship between two classes. Aggregation implies that the whole is conceptually at a higher level than the local, and the association implies that two classes are conceptually at the same level. Aggregations are also converted to an instance-scoped variable in java.

The difference between association and aggregation is purely conceptual, and is strictly reflected in semantics. Aggregation also implies that there are no loops in the instance diagram. In other words, it can only be a one-way relationship.

Figure F

Synthesis (composition)

Synthesis in UML class diagram relationships (Figure g) is a special form of aggregation that implies a "local" lifetime responsibility within the "whole". The composition is also unshared. Therefore, although the local does not have to be destroyed with the overall destruction, but the overall responsibility to maintain a local survival, or be responsible for destroying it. Local cannot be shared with other whole. However, the whole can transfer ownership to another object, which will then assume the lifetime responsibility.

The relationship between employee and timecard may be better represented as "compositing" rather than "associative".

Figure G

Generalization (generalization)

Generalization in UML class diagram relationships (Figure h) represents a 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.

Figure h

Implementation (Realization)

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

Review: Through the Java code and UML can be very clear understanding of these relationships, related to 3 kinds of this comparison, mainly to understand the dependency, association, generalization and implementation of these 4 relationships

Diagram of six UML class diagram 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.