Original address: http://blog.csdn.net/maybehelios/article/details/2038685
The relationships between classes
1. Species: Generalization (generalization), Dependency (dependency), Association (Association), Aggregation (aggregation relationship), composition (composition relationship).
2. Among them, aggregation (aggregation relation), composition (synthetic relation) belong to Association (association relation), and are Special Association association relation.
3. Generalization (generalization) is represented as an inheritance or implementation relationship (is a). The concrete form is the inheritance relation between the class and the class, the inheritance relation between the interface and the interface, and the implementation relation of the class to the interface.
4. The Association association is represented as a variable (has a). A join between a class and a class that enables a class to know the properties and methods of another class. For example, if a depends on B, then B is represented as a global variable.
Association relationships have two-way associations and one-way associations. Bidirectional affinity: Two classes are aware of the public properties and operations of another class. One-way Association: Only one class knows the public properties and operations of another class.
Most associations should be unidirectional, one-way relationships easier to establish and maintain, and help find classes that can be taken.
5. Aggregation (aggregation relation) is a kind of association relation, and it is a strong association relation. The aggregation relationship is the relationship between the whole and the individual. The two classes of the common relational relationship are at the same level, while the two classes of the aggregation relationship are at different levels, one is the whole and the other is part. At the same time, it is a weak "owning" relationship. This shows that a object can contain a B object, but the B object is not part of a object. Specifically, if a is aggregated by B, it behaves as a global object with B, but the B object may not be created at the moment a is created.
6. Composition (combinatorial relationship) is a kind of association relation, which is stronger than aggregation relationship. It requires that an object representing the whole in an ordinary aggregation relationship be responsible for the life cycle of the object that represents the part. Composition (combinatorial relationship) is a strong "owning" relationship, which embodies the relationship between the strict part and the whole, and the life cycle of the part and the whole is consistent. If a is made up of B, it behaves as a global object with B, and the B object is created at the moment a is created.
7. A Dependency (dependency) is represented as a parameter in a function (use a). is a connection between a class and a class, which means that one class relies on the definition of another, and one class changes that affect the other. For example, if a depends on B, then B is represented as a local variable, a method's parameter, or a call to a static method.
Correlation, composition, aggregation, dependency comparison [go]