Contains is the relationship between a set and a set, also called a subset relationship. The basic meaning is similar to implication, implication, forgiveness, and relationship adjective. The element between the element and the set is called an element belonging to the set example A = {1, 2}, B = {1, 2, 3}. then 1, A, 2,, 3, B belongs to the relationship between elements and sets. for example, element a belongs to set A and is recorded as a, A belongs to the symbol, it is used for the inclusion of elements between A set and A set. if any of the contained elements of set A is the relationship between the set and the set, it is also called A subset relationship. The basic meaning is similar to implication, implication, forgiveness, and relationship adjective.
An element or an element between a set belongs to a set.For example, if A = {1, 2}, B = {1, 2, 3}, 1, A, 2, A, and 3, B belong to the relationship between elements and sets. for example, element a belongs to set A and is recorded as "a" and "A" belongs to the symbol ", which is used between elements and sets.
The inclusion between a set and a set is called inclusion.If any element of set A is the element of set B, set A is called the subset of set B, it is recorded that A contains B or B. It contains A null set and is included in any set. if the element of A is A subset of B, in addition, if at least one element in B does not belong to A, set A is called the real subset of set B and is recorded as A which actually contains B or B and actually contains.
There are many differences between combination and aggregation. The difference is not in form, but in essence:
For example, class A contains A reference of Class B. When an object of Class A disappears, the reference of Class B also points to the object (no reference points to it, this is called a combination. if B points to another object, another reference points to it. this is called aggregation.
In real life:
People and hands and feet are combined, because when a person dies, the hand will no longer exist. People interact with their computers.
- Class Hand {
- }
- Class Computer {
- }
- Combination:
- Class Person {
- Private Hand hand;
- Public Person (){
- Hand = new Hand ();
- }
- }
- Aggregation:
- Class Person {
- Private Computer computer;
- Public setComputer (){
- Computer = new Computer ();
- }
- }
Aggregation is a strongly combined relationship.
Differences and links between combination and aggregation:
First, the relationship between the entire and the part is better. for the combination, if the part is lost, the whole will not exist.
Code implementation:
Combination: instantiate the part in the constructor. this part cannot be shared by other instances. The overall and partial lifecycle are synchronized. The aggregate link can be initialized in the constructor in the form of parameter passing.
From the database perspective: Composite relationship: Cascade deletion is required, but aggregation relationship is not required.
After reading these relationships, we can get a general understanding. In fact, the composite relationships in java are the include relationships in mathematical sets.
There is a great similarity between the combination and the two meanings.
We can easily understand the statements in some programs by using include:
A a = new ();
B B = new B ();
C c = new C (B );
C contains B, and B contains.
If it is represented by a mathematical formula
A belongs to B, B belongs to c
This makes it easy to understand the true meaning of these three sentences:
That is, all functions and attributes of a, B, can be directly used.
All functions and attributes in B. c can be directly used.
It's like c is a person B is a hand c is a finger one contains
This layer-by-layer composite relationship uses data, which is quite understandable in mathematics.