Six of the relationship between software design in UML-UML

A, UML in the six relations

In UML class diagram, common are the following relation: Generalization (the Generalization), implement (Realization), association (Association or), the polymerization (Aggregation), combination (Composition), dependency (Dependency).

image

1.1, inheritance - Generalization (Generalization)

It refers to a class (called a subclass, sub-interface) inherit another class (called the parent, the parent Interface) functions, and can increase the capacity of its own new features, inheritance is a class with a class or interface the most common relationship between the interface; in Java using the extends keyword.

clip_image001

[Generalization] that is an inheritance, a special relationship with the general representation that specifies how special subclass of all the features and behavior of the parent class. For example: the owl is a bird, a bird that is also characteristic in common owl.

[] With the arrow pointing triangle the solid line arrow, arrows pointing to the parent class.

Description class diagram above has a mouth bird wings, feathers, and other attributes. Fly, will be called twitter, then there are these methods. The owl has big eyes and the ability to catch mice, it is its own characteristics.

1.2, to achieve the relationship (Realization)

Refers to a class class implements the interface Interface (may be more) function; implementation is the most common relationships between classes and interfaces; such relationships in Java clearly identified by the keyword implements.

clip_image003

[Realize] relationship is a relationship of classes and interfaces, class representation is to achieve all of the features and behavior of the interface.

[] The dotted line with triangular arrows pointing arrow, the arrow points to the interface.

Description IFly figure above is an interface, the interface has a constant for the time, speed and the like, there is a fly method. After FlyImpl inherited this IFly interface need to implement fly method, while realizing class can have its own properties and methods.

1.3, depending on (the Dependency)

Can be simply understood, the use of A class is a class B to another, and this relationship is contingent use, the temporary, very weak, but the change will affect the type of A B; such a person to cross the river , need to borrow a boat, then the relationship between people and is dependent on the ship; code performance level, as a parameter for the class B, class a properties are used in a method process;

clip_image005

[Dependency] is a relationship of use, that is a class implementation needs assistance of another class, so try not to use two-way interdependence.

[Code manifestations of local variables, parameters, or method calls to the static method

] [Pointing arrow and a dotted line with an arrow, pointing by the user

Description Bird setFly class has a method, which requires the user to use to achieve IFly interface, then this relationship is dependency.

1.4, the association

He embodies the two categories, one semantic level or between classes and interfaces strong dependencies, such as me and my friend; this relationship is stronger than dependence, there is no chance of dependency, not a temporary relationship , usually long-term, but also the general relationship between the two are equal, the association can be unidirectional, bidirectional; performance at the code level, appears to be associated with the class a and class B in the form of the associated class attribute, it may a class is associated with a referenced type is associated with the class B global variables;

clip_image007

[Association] is a relationship of have, it makes a class knows another class attributes and methods; such as: student teacher, husband and wife may be associated with a bi-directional, it can be one-way. Bidirectional arrow association may be two or no associated arrow, there is a one-way arrow.

[Code] reflects the member variables

[] Points with arrows and solid line arrows general, pointing to the owner

Description of the type having a fly IFly Bird class attribute, it is necessary to provide the interface IFly. Bird objects will use to achieve IFly interface complete fly method.

 

1.4.1, bidirectional associations

Both sides know each other's existence, we can call each other's public properties and methods.

clip_image002

Relationship [relationship] both have associated themselves to each other through the property associated to access each other's properties and methods.

[Code] reflects the member variables

[Pointing arrow and a solid line] without arrows connecting both

Description Use in China can only marry a wife, a husband, a husband can only take a wife.

 

1.4.2, associate themselves

Own their own association, but this situation is also useful to appear relatively small.

clip_image004

[Self] relationship between the two sides has an associated, to visit each other's properties and methods through their property on their own associated reference.

[Code] reflects the member variables

[] Points and the solid line arrows by arrows connected with their normal

Description In Inception, the actors need to re-dream the dream, this dream dreams keep up with the figure depicts very consistent.

 

1.5, the polymerization (Aggregation)

The polymerization is a special case of the relationship, he embodied integral with the part, have the relationship, i.e., has-a relationships, in which case the entire portion between the separable and are, they may have their own life cycle, portions may belong to more whole objects can be shared by a plurality of integral objects; for example, relations with CPU computer company and employees; performance at the code level, and relationships are the same, can only be distinguished from the semantic level;

clip_image009

[] Aggregation relationship is the relationship with the whole portion, and a whole portion can leave alone. Such as car tires and the relationship between the whole and parts, tires leave the car may still exist. Aggregation relationship is a relationship is strong association relationship; correlation and aggregation syntactically indistinguishable, must examine specific logic.

[Code] reflects the member variables

[Arrow] and point to a solid line with a hollow diamond, diamond point to overall

Description birdChild a bird have a lot of baby birds, so self-referential. Birds have a lot of different numbers and colors of feathers, so the reference relationship is 0 ~ *.

1.6, the combination (Composition)

Combinations are associated with a special case of a relationship, the relationship of his reflect contains-a, this relationship more than polymerization, also called polymerization strong; he also reflects the relationship between the whole and partial, but this time with the whole It is inseparable part of the whole life cycle of the end will mean the end of the life cycle of parts; for example, you and your brain; manifested in the code level, and relationships are the same, can only be distinguished from the semantic level;

clip_image011

[Composition] is an integral relationship with the part of the relationship, but some can not leave alone a whole. Such as companies and sectors and is part of the overall relationship, no company would not exist departments. Combination relationship is a relationship, the relationship is even stronger than the aggregation relationship, which requires a common aggregation relationship represents the life cycle of an object represents the portion of the object is responsible for the overall.

[Code] reflects the member variables

[] Points and the solid line arrows with solid diamond, diamond point whole

Description of a school composed of a plurality of classes, class left the school would not exist, while leaving school class is not established. Like this need not be separated by a combination relationship.

Comprehensive example

clip_image013

For inheritance, to achieve the two relationships is not much doubt that they embodied in a class with the class, or vertical relationship between the classes and interfaces; the other four who embodies the relationship between the class and class, or references between classes and interfaces lateral relations, it is more difficult to distinguish, there are many relationships between things in order to prepare is hard to define, mentioned earlier, these types of relationships are semantic level, it does not fully distinguish between various levels from the code relationship; but in general, how strongly manifested after some relations as follows: to achieve generalization => composition> polymerization> related> dependent.

Transfer: https://www.cnblogs.com/hoojo/p/uml_design.html

Guess you like

Origin www.cnblogs.com/onetwo/p/12552060.html