contains a collection and a collectionBetweenthe relationship, also calledSubsetrelationships. Basic meaningis near the same as implication, implication, inclusion,Relationshipadjectives.
the inclusions between elements and collections are called elements belonging to the collectionExample a={1,2},b={1,2,3} then 1∈a,2∈a,3∈b belongs to the relationship between the element and the set, for example, element a belongs to collection A, and a∈a belongs to the symbol: ∈, used between the element and the collection
the inclusion between the collection and the collection is called the containingIf any of the elements of collection A are elements of set B, then the set a is called a subset of Set B, and a contained in B or B contains an empty set that is contained by any one by one collection, which is a subset of any set if the element of set A is a subset of Set B, and at least one of the elements in B does not belong to a So the set A is called a true subset of Set B, which is recorded as a true inclusion of B or B really contains a.
There is a big difference between composition and aggregation, not in form, but in nature:
For example, a class contains a reference B of Class B, when an object of Class A dies, b the object that the reference points to also dies (no reference to it, it becomes a garbage object), this is called the combination, and the object that B points to has another reference to it, which is called aggregation.
In real life:
Man and hand, the foot is a combination of relations, because when the human death of the hand of the future is no longer exist. The person and his computer are the aggregation relationship.
- Class hand{
- }
- Class computer{
- }
- Combination:
- Class person{
- Private Hand Hand;
- Public person () {
- Hand = new Hand ();
- }
- }
- Polymerization:
- Class person{
- Private computer computer;
- Public Setcomputer () {
- Computer = new computer ();
- }
- }
It can be said that aggregation is a strong combination of relationships
Differences and linkages between composition and aggregation:
First of all, the relationship between the whole and the part, the combination of a stronger relationship, for the combined relationship, if the loss of part, the whole will not exist.
The code implementation looks:
Composition: The part that is instantiated in the overall constructor, which cannot be shared by other instances. The whole and part of the life cycle are synchronized. The part of the aggregation relationship can be initialized in the form of parameter passing in the constructor.
From a database perspective: Combinatorial relationships: cascade deletions are required, and aggregation relationships are not required.
After reading these relationships, we can get a sense of comprehension. In fact, the combinatorial relationship in Java is the inclusion relationship of a mathematical set.
There is a great similarity between the combination and the two meanings
It is easy to understand the statements in some programs with the inclusion of:
A a=new a ();
b b=new B (a);
C c=new C (b);
In the three sections of code, C contains the b,b containing a
If you use a mathematical formula to express
A belongs to B,b belongs to C
This makes it easy to understand what these three words really mean:
Is that all the functions and attributes B in a have b that can be used directly
All functions and attributes C in B are available directly with C
It's like a C is a person B is a hand C is a finger that contains a
Such a layer of the combined relationship with the data is very good understanding of mathematics and profound AH
Differences and linkages between Java composition and aggregation and the inclusion relationships of collections on the data