UML Relationships (generalization, implementation, dependency, association (aggregation, composition))

Source: Internet
Author: User

UML is constructed quickly with 3 types:

(1) Things (4 kinds): Structure things, act on things, group things, annotate things

(2) Relationship (4 kinds): Generalization relation, realization relation, dependency relation, correlation relation

(3) Figure (10 kinds): Use case diagram, Class diagram, object graph, Package diagram, Component diagram, deployment diagram, state diagram, activity diagram, sequence diagram, collaboration diagram

Things are the abstractions of the most representative elements of a model; relationships combine things together; graphs gather the relevant things.

(2) Relationship (4 types)

The relationships between classes and classes , classes and interfaces, interfaces and interfaces in UML are : generalization (generalization)Relationship , Association(Association)Relationship ( Association , Aggregation , composition ), dependency(dependency)relationship,Implementing (Realization) Relationships. 

A generalization (generalization) relationship is the ability of a class (called a subclass, a sub-interface) to inherit another class (called a parent class, a parent interface) and to increase its own new functionality, which is the most common relationship between a class and a class or interface and interface; In Java, this type of relationship is clearly identified by the keyword extends , which is generally not controversial at design time.

The implementation (realization) relationship refers to a class class that implements the interface interface (which can be multiple), and the implementation is the most common relationship between classes and interfaces; in Java such relationships are explicitly identified by the keyword implements , is generally not controversial at design time;


Dependency (dependency) relationship :is also a connection between classes and classes.Represents a class that relies on the definition of another class.Dependencies are alwaysOne wayOf. It can be simply understood that a class A uses another Class B, which is contingent, temporary, and very weak, but changes in class B affect A; For example, if someone wants to cross the river and borrow a boat, then the relationship between the man and the ship is dependent; At the code level, Class B is used as a parameter by Class A in some method methods.
in theJavain.The dependency relationship is reflected in: Local Variables,parameters in the method,and calls to a static method.



Association (Association) Relationship :Represents a join between a class and a class,It enables a class to know the properties and methods of another class.
Associations can use a single arrow to represent one-way associations,Use a double or no arrows to indicate a bidirectional association,Bidirectional affinity is not recommended.Association has two endpoints,At each endpoint can have a cardinality,The class that represents this association can have several instances.
Common cardinality and meaning:
0..1:0Or1An instance.
0..*:There is no limit to the number of instances.
1:There can only be one instance.
1..*:There is at least one instance.

He embodies a strong dependency between the two classes, or the semantic level of the class and interface, such as me and my friends; this relationship is more than relying on the contingency, the relationship is not temporary, generally long-term, and the relationship between the two sides is generally equal, manifested in the code level, To be associated class B in the form of a class attribute in the association Class A, or the association Class A refers to a type is associated with the class B global variables; in the Java Language, association relationships are implemented using instance variables .  




Aggregation (aggregation) Relationship : A special case of association relationship , which is a strong association . aggregation is the relationship between the whole and the individual , that is, the relationship between the whole and the part is has-a , they can have their own life cycle , some can belong to a plurality of whole objects, can also be shared for multiple whole objects , such as computer and CPU, The relationship between the company and its employees, and the expression at the code level, and the association is consistent, can only be differentiated from the semantic level;

.   java   syntax is not an associative and aggregated < Span style= "color: #000080;" >. &NBSP;

Association The two classes are at the same level ,   and the two classes in the aggregation relationship are at an unequal level   one represents whole   one represents part &NBSP;



 
combination ( composition) Relationship (composition) :   is also a special case of association, and he embodies a , ; like you and your brain; Synthetic relationships cannot share .  . The behaves at the code level, and the association is consistent and can only be differentiated from the semantic level.

The combination is almost identical to the aggregation, the only difference is that the "part" cannot be separated from the "whole", that is, the "part" of the life can not be longer than the "whole".


Summarize:

There is little doubt about the inheritance and realization of these two relationships, they embody a kind of class and class, or the vertical relationship between the class and the interface; the other four relationships embody the class and class, or the reference between the class and the interface, the transverse relation, is more difficult to distinguish between, there are many things between the relationship to prepare for positioning is very difficult, These relationships are semantically level, so it is not possible to completely differentiate the relationships from the code level, but in general, the following relationships are represented by: combination > Aggregation > Association > Dependency .

============================

Reprinted from http://justsee.iteye.com/blog/808799

UML Relationships (generalization, implementation, dependency, association (aggregation, composition))

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.