You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/posts/cpp-learn.md
+46-1Lines changed: 46 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3022,4 +3022,49 @@ int main()
3022
3022
3023
3023
return 0;
3024
3024
}
3025
-
```
3025
+
```
3026
+
3027
+
## Others
3028
+
## 1. Object Relationships
3029
+
- Learned about some different kinds of relationships between two objects.
3030
+
3031
+
- The process of building complex objects from simpler ones is called **object composition**.
3032
+
- There are two types of object composition: `composition`, and `aggregation`.
3033
+
-**Composition** exists when a member of a class has a part-of relationship with the class. In a composition relationship, the class manages the existence of the members.
3034
+
- To qualify as a composition, an object and a part must have the following relationship:
3035
+
- The part (member) is part of the object (class)
3036
+
- The part (member) can only belong to one object (class) at a time
3037
+
- The part (member) has its existence managed by the object (class)
3038
+
- The part (member) does not know about the existence of the object (class)
3039
+
- Typically implemented via normal member variables, or by pointers where the class manages all the memory allocation and deallocation. If you can implement a class as a composition, you should implement a class as a composition.
3040
+
3041
+
-**Aggregations** exists when a class has a has-a relationship with the member. In an aggregation relationship, the class does not manage the existence of the members.
3042
+
- To qualify as an aggregation, an object and its parts must have the following relationship:
3043
+
- The part (member) is part of the object (class)
3044
+
- The part (member) can belong to more than one object (class) at a time
3045
+
- The part (member) does not have its existence managed by the object (class)
3046
+
- The part (member) does not know about the existence of the object (class)
3047
+
- Typically implemented via pointer or reference.
3048
+
3049
+
-**Associations** are a looser type of relationship, where the class uses-an otherwise unrelated object.
3050
+
- To qualify as an association, an object and an associated object must have the following relationship:
3051
+
- The associated object (member) is otherwise unrelated to the object (class)
3052
+
- associated object (member) can belong to more than one object (class) at a time
3053
+
- The associated object (member) does not have its existence managed by the object (class)
3054
+
- The associated object (member) may or may not know about the existence of the object (class)
3055
+
- May be implemented via pointer or reference, or by a more indirect means (such as holding the index or key of the associated object).
3056
+
3057
+
- In a **dependency**, one class uses another class to perform a task. The dependent class typically is not a member of the class using it, but rather is temporarily created, used, and then destroyed, or passed into a member function from an external source.
3058
+
3059
+
- In a **container** class one class provides a container to hold multiple objects of another type. A value container is a composition that stores copies of the objects it is holding. A reference container is an aggregation that stores pointers or references to objects that live outside the container.
3060
+
3061
+
-**std::initializer_lis**t can be used to implement constructors, assignment operators, and other functions that accept a list initialization parameter.
3062
+
- std::initializer_list lives in the <initializer_list> header.
0 commit comments