UML describes the relationship between objects and classes by dependency, association, aggregation, composition, and generalization ), implementation.
Dependency(Dependency): Element A changes will 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 (Generalization): The Inheritance (special individual is kind of general individual) relationship, which does not need to be explained. In UML, a solid line with a hollow arrow is used to represent the generalization relationship. The arrow points to a general individual.
Implementation (Realize): 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 (Association): The structured relationship between elements is a weak relationship. The associated elements can be considered independently. In UML, the association relationship is represented by a solid line, and the arrow points to the dependent element.
Aggregate (Aggregation): A special case of association, indicating the relationship between the partial and the overall (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.
GroupUnion (Composition): A combination is a variant of the aggregation relationship, indicating a stronger combination 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. The diamond header points to the whole.
The dependency relationship is the weakest, while Association, aggregation, and composition indicate that the relationship is enhanced in turn. In other words, association, aggregation, and combination are all dependent relationships. Aggregation indicates the association between objects and partial relationships, the combination indicates the aggregation of the same lifecycle relationship between the whole and the part.
In a word, the relationship between Association and dependency describes the call relationship between objects, and the relationship describes the structural relationship between objects.
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.
1.1.1 dependency: dotted arrow
1. Dependency is also the connection between classes
2. Dependency is always one-way. (# Add Note: Avoid bidirectional dependency. Generally, there should be no two-way dependency.
3. Dependency is embodied in local variables, method parameters, or calls to static methods in Java or C ++.
class Person {void buy(Car car) { ... } }
650) This. width = 650; "src =" http://pic002.cnblogs.com/images/2012/285763/2012061315032141.jpg "alt =" 2012061315032141.jpg"/>
Expression method: add an arrow to the dotted line
Feature: when there is a usage relationship between a class and a class, the dependency is dependent. Different from the association relationship, dependency does not have an "having relationship", but is a "acquaintance relationship ", only in a specific place (such as a method body)
1.1.2 Association: Solid-line arrows
1. associations are the associations between classes. They enable one class to know the attributes and methods of another class.
2. association can be bidirectional or unidirectional (# Add has its own Association ). Two-way association can have two arrows or no arrows, and one-way Association has one arrow.
3. In Java or C ++, associations are implemented by using member variables.
Class apprentice {}; class Tang Seng {protected: List <apprentice> tdlist ;};
650) This. width = 650; "src =" http://pic002.cnblogs.com/images/2012/285763/2012061315034351.jpg "alt =" 2012061315034351.jpg"/>
Representation Method: solid arrow
Feature: it indicates the dependency between a class and a class or between a class and an interface. It is expressed as "having relationship". The code can be expressed as an instance variable.
1.1.3 aggregation: expressed with hollow diamond Header
1. An aggregation relationship is a strong association relationship.
2. Aggregation is the relationship between the whole and the part. For example, an automobile consists of an engine, a tire, and other parts.
3. The aggregation relationship is also implemented through member variables. However, the two classes involved in the Association are at the same level, while the two classes in the aggregation relationship are at different levels. One Class represents the whole, and the other class represents the part.
4. Association and aggregation cannot be distinguished only from Java or C ++ syntax, and the logical relationship between classes involved must be investigated.
Class engine {}; class tire {}; class car {protected: engine; protected: Tire tyre [4] ;};
650) This. width = 650; "src =" http://pic002.cnblogs.com/images/2012/285763/2012061315041541.jpg "alt =" 2012061315011641.jpg"/>
Expression method: hollow Diamond Head
Features: It is a special case of association, reflecting part-overall relationship, which is a weak relationship of ownership; the whole and part can have different lifecycles; it is a weak Association;
1.1.4 composition: solid line representation with solid diamond Header
1. The compositing relationship is a kind of association relationship, which is stronger than the aggregation relationship.
2. It requires that the object representing the whole in a common aggregation relationship be responsible for representing the lifecycle of some objects.
Class limb {}; class member {protected: limb Limb [4] ;};
650) This. width = 650; "src =" http://pic002.cnblogs.com/images/2012/285763/2012061315044438.jpg "style =" margin: 0px; padding: 0px; Border: 0px; "/>
It is usually indicated by solid diamond and solid line arrows.
Feature: It is a special case of association, and also reflects part-overall relationship, which is a strong "having relationship". The whole and part have the same lifecycle, is strongly correlated;
Generalization (generalization and implementation ):Represents the inheritance relationship between classes, the inheritance relationship between interfaces, or the Implementation relationship between classes on interfaces. A general relationship refers to a subclass pointing to the parent class, or pointing from the class implementing the interface to the implemented interface, in the opposite direction of inheritance or implementation. As shown in:
650) This. width = 650; "src =" http://pic002.cnblogs.com/images/2012/285763/2012062013291388.jpg "style =" margin: 0px; padding: 0px; Border: 0px; "/>
Figure: general link
1.1.5 generalization: solid line representation with hollow arrows
Generalization (FigureH) 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.
Generalized relationships indicate the inheritance relationships between classes and interfaces. Figure H
650) This. width = 650; "src =" http://pic002.cnblogs.com/images/2012/285763/2012061315050938.gif "style =" margin: 0px; padding: 0px; Border: 0px; "/>
1.1.6 implementation (realization): Expressed by hollow arrows and dotted lines
Instance (FigureI) 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
650) This. width = 650; "src =" http://pic002.cnblogs.com/images/2012/285763/2012061315052227.gif "style =" margin: 0px; padding: 0px; Border: 0px; "/>
This article is from the "learninghard" blog and will not be reproduced!
Description and examples of various types of UML class diagram symbols