Similarities and differences between associations, dependencies, and aggregates in UML

Source: Internet
Author: User
1. Join: connect model elements and linked instances, represented by a solid line;
2. Dependency: indicates that an element depends on another element in some way and is expressed by a dotted line and an arrow;
3. Aggregation: the relationship between the whole and the part, expressed by a solid line and a hollow diamond;
4. Composition: indicates the relationship between the whole and the part, expressed by a solid line and a solid rhombus;
(For similarities and differences between associations, dependencies, and aggregation, see the post description)
5. generalization (inheritance): represents the general and special relationship, expressed by a solid line and a hollow arrow;
6. implementation: represents the relationship between classes and interfaces, expressed by a dotted line and a hollow arrow; similarities and differences between associations, dependencies, and aggregation: (a book in Java object-oriented programming, Author: Sun weiqin Source: www.javathinker.org)
) When creating an object model, it is easy to confuse dependencies, associations, and clustering relationships. When there is a dependency, association, or aggregation relationship between object A and object B, object a may call the method of object B, which is the same among the three relations. In addition, they have different features. 1. the characteristics of dependency relationship for two relatively independent systems, when one system is responsible for constructing instances of another system or dependent on services of the other system, the two systems are mainly dependent on the relationship, for example, machines producing parts and zero parts
The machine is responsible for constructing part objects. For example, a rechargeable battery and a Charger are charged by a charger. For example, bicycle and pump, the bicycle is inflated through the pump.
Figure 1-39 shows the block charts of the bicycle and pump classes. Figure 1-39 dependencies between the bicycle class and the pump class: dependencies between the bicycle class and the pump class. You do not need to define variables of the pump type in the bicycle class. The bicycle class is defined as follows: public class bicycle {
/** Inflatable tires */
Public void expand (pump ){
Pump. Blow ();
}
} In our daily life, a bicycle is usually not equipped with a special gas pump, but a gas pump from a nearby garage when it needs to be inflated. In the program code, the expand () method of the bicycle class has a pump type parameter. The following code indicates that a bicycle has been inflated in two garages: mybicycle. Expand (pumpfromrepairshed1); // It is inflated in the first garage.
Mybicycle. Expand (pumpfromrepairshed2); // inflatable to the second garage several days later. 2. correlated features
For two relatively independent systems, when the instance of one system has a fixed ing relationship with some specific instances of the other system, the two systems are associated. For example, for customers and orders, each order corresponds to a specific
For specific customers, each customer corresponds to some specific orders. For example, for companies and employees, each company corresponds to some specific employees, each employee corresponds to a specific company, and for example, bicycles and owners, each bicycle belongs
For specific owners, each master has a specific bicycle. Figure 1-40 shows the association between the master and the bicycle. There is no fixed correspondence between the rechargeable battery and the charger.
There is no fixed correspondence. Figure 1-40 correlation between the master and bicycle: there is an association between the person class and the bicycle class, which means that a member variable of the bicycle type needs to be defined in the person class. The following is the definition of the person class: public class person {
Private bicycle; // The bicycle owner's public bicycle getbicycle (){
Return bicycle;
}
Public void setbicycle (bicycle ){
This. Bicycle = bicycle;
}
/** Go to work by bike */
Public void gotowork (){
Bicycle. Run ();
}
} In your current life, when you ride a bicycle to go to work, you only need to launch your own bicycle from home to get on the road. It is not like hitting a bicycle, when you need to get angry, you have to go around to find a garage. Therefore
In the gotowork () method of the person class, call the run () method of its own bicycle object. Assume that the gotowork () method adopts the following definition:/** go to work by bicycle */
Public void gotowork (bicycle ){
Bicycle. Run ();
} That's like borrowing a bicycle before you go to work. 3. clustering relationship features when system A is added to system B and becomes a part of system B, system B and system A are clustered. For example, a bicycle is clustered with its bell rings, leaders, tires, steel rings, and brakes,
Because the ring tones are part of a bicycle. People and bicycles are not clustered because they are not made up of bicycles. If people must be made up of humans, they should be made up of heads, trunks, and limbs. Therefore
See. You can differentiate associations and clustering relationships based on semantics. The difference between clustering and association is also manifested in the following aspects: (1) for two objects with Association, in most cases, the two objects have an independent life cycle. For example, when a bicycle and its owner do not exist, its owner still exists, and vice versa. However, in some cases, one party restricts the lifecycle of the other party. For example, if a customer or an order does not exist, its order will lose its meaning. (2)
For two objects with a clustering relationship (especially a strong clustering relationship), the overall object will restrict the lifecycle of the object it is composed. Objects of the partial classification cannot exist independently. its lifecycle depends on the object of the entire class.
The lifecycle disappears as a whole. For example, if Mr. Wang's bicycle is stolen, all components of the bicycle do not exist, unless Mr. Wang happens to put some detachable components (such as the bell and the seat
PAD.
However, when program code is used to represent the Association and clustering relationships, the two are similar. Figure 1-41 shows the clustering relationship between bicycle bicycles and bell rings. Figure 1-41 aggregation relationship between bicycles and rings 1-6 is the source program of the bicycle class. Routine 1-6 bicycle. javapublic class bicycle {
Private Bell bell; Public Bell getbell (){
Return bell;
} Public void setbell (Bell bell ){
This. Bell = bell;
}/** Send a ringtone */
Public void alert (){
Bell. Ring ();
}
} A member variable of the Bell type is defined in the bicycle class. The bicycle class uses its own bell member variable to send a ringtone, which defines the member variable of the bicycle type in the person class, the person class uses its own bicycle member variables to go to work very similar. 4. The feature composition of a consortium is a relationship between two classes. The overall class is composed of a department class, and the department class must exist, this relationship means that the destruction of the overall class will also destroy the partial category posts from: http://www.cnblogs.com/ForEverKissing/archive/2007/12/13/993818.html

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.